Rewrite Lua autoexec
Now put autoexec.lua in one of the mods folders, it now has all of the capabilities of a full mod without the crashes and weird bugs, which is pretty awesome.
This commit is contained in:
parent
ae3271d98a
commit
4e63798f00
|
@ -138,6 +138,9 @@ void djui_panel_host_mods_create(struct DjuiBase* caller) {
|
|||
struct DjuiBase* layoutBase = &paginated->layout->base;
|
||||
for (int i = 0; i < gLocalMods.entryCount; i++) {
|
||||
struct Mod* mod = gLocalMods.entries[i];
|
||||
if (mod_get_is_autoexec(mod)) {
|
||||
continue;
|
||||
}
|
||||
if (isRomHacks != (mod->incompatible && strstr(mod->incompatible, "romhack"))) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -18,10 +18,12 @@ void djui_panel_modlist_create(UNUSED struct DjuiBase* caller) {
|
|||
gDjuiModList = NULL;
|
||||
}
|
||||
|
||||
// only create if we have mods
|
||||
if (gActiveMods.entryCount == 0) { return; }
|
||||
u8 autoexecMod = mods_has_autoexec_mod();
|
||||
|
||||
f32 bodyHeight = (gActiveMods.entryCount * 32) + (gActiveMods.entryCount - 1) * 4;
|
||||
// only create if we have mods
|
||||
if (gActiveMods.entryCount - autoexecMod == 0) { return; }
|
||||
|
||||
f32 bodyHeight = (gActiveMods.entryCount * 32) + (gActiveMods.entryCount - 1 - autoexecMod) * 4;
|
||||
struct DjuiThreePanel* panel = djui_panel_menu_create(DLANG(MODLIST, MODS));
|
||||
djui_three_panel_set_body_size(panel, bodyHeight);
|
||||
gDjuiModList = panel;
|
||||
|
@ -40,6 +42,7 @@ void djui_panel_modlist_create(UNUSED struct DjuiBase* caller) {
|
|||
|
||||
for (int i = 0; i < gActiveMods.entryCount; i++) {
|
||||
struct Mod* mod = gActiveMods.entries[i];
|
||||
if (mod_get_is_autoexec(mod)) { continue; }
|
||||
|
||||
struct DjuiFlowLayout* row = djui_flow_layout_create(body);
|
||||
djui_base_set_size_type(&row->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||
|
|
|
@ -288,13 +288,6 @@ void smlua_init(void) {
|
|||
gLuaActiveMod = NULL;
|
||||
gLuaLoadingMod = NULL;
|
||||
}
|
||||
|
||||
#ifdef DEVELOPMENT
|
||||
// autoexec
|
||||
if (path_exists("autoexec.lua")) {
|
||||
smlua_exec_file("autoexec.lua");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void smlua_update(void) {
|
||||
|
|
|
@ -20,6 +20,11 @@ size_t mod_get_lua_size(struct Mod* mod) {
|
|||
return size;
|
||||
}
|
||||
|
||||
bool mod_get_is_autoexec(struct Mod* mod) {
|
||||
if (!strcmp(mod->name, "autoexec") || !strcmp(mod->name, "autoexec.lua")) { return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
static void mod_activate_bin(struct ModFile* file) {
|
||||
// copy geo name
|
||||
char geoName[64] = { 0 };
|
||||
|
|
|
@ -40,6 +40,7 @@ struct Mod {
|
|||
};
|
||||
|
||||
size_t mod_get_lua_size(struct Mod* mod);
|
||||
bool mod_get_is_autoexec(struct Mod* mod);
|
||||
void mod_activate(struct Mod* mod);
|
||||
void mod_clear(struct Mod* mod);
|
||||
bool mod_load(struct Mods* mods, char* basePath, char* modName);
|
||||
|
|
|
@ -49,6 +49,13 @@ u16 mods_get_enabled_count(void) {
|
|||
return enabled;
|
||||
}
|
||||
|
||||
u8 mods_has_autoexec_mod(void) {
|
||||
for (u16 i = 0; i < gLocalMods.entryCount; i++) {
|
||||
if (mod_get_is_autoexec(gLocalMods.entries[i])) { return TRUE; }
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void mods_local_store_enabled(void) {
|
||||
assert(sLocalEnabledPaths == NULL);
|
||||
struct LocalEnabledPath* prev = NULL;
|
||||
|
@ -106,6 +113,14 @@ bool mods_generate_remote_base_path(void) {
|
|||
return true;
|
||||
}
|
||||
|
||||
static struct Mod* get_autoexec_mod(void) {
|
||||
for (u16 i = 0; i < gLocalMods.entryCount; i++) {
|
||||
if (mod_get_is_autoexec(gLocalMods.entries[i])) {
|
||||
return gLocalMods.entries[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mods_activate(struct Mods* mods) {
|
||||
mods_clear(&gActiveMods);
|
||||
|
||||
|
@ -116,8 +131,11 @@ void mods_activate(struct Mods* mods) {
|
|||
if (mod->enabled) { enabledCount++; }
|
||||
}
|
||||
|
||||
// is joining a game and has an autoexec mod
|
||||
bool autoexec = mods == &gRemoteMods && mods_has_autoexec_mod();
|
||||
|
||||
// allocate
|
||||
gActiveMods.entries = calloc(enabledCount, sizeof(struct Mod*));
|
||||
gActiveMods.entries = calloc(enabledCount + autoexec, sizeof(struct Mod*));
|
||||
if (gActiveMods.entries == NULL) {
|
||||
LOG_ERROR("Failed to allocate active mods table!");
|
||||
return;
|
||||
|
@ -126,8 +144,9 @@ void mods_activate(struct Mods* mods) {
|
|||
// copy enabled entries
|
||||
gActiveMods.entryCount = 0;
|
||||
gActiveMods.size = 0;
|
||||
for (int i = 0; i < mods->entryCount; i++) {
|
||||
struct Mod* mod = mods->entries[i];
|
||||
for (int i = 0; i < mods->entryCount + autoexec; i++) {
|
||||
// checks if the mod is out of the remote mods bounds and if so, use the autoexec mod
|
||||
struct Mod* mod = i == mods->entryCount ? get_autoexec_mod() : mods->entries[i];
|
||||
if (mod->enabled) {
|
||||
mod->index = gActiveMods.entryCount;
|
||||
gActiveMods.entries[gActiveMods.entryCount++] = mod;
|
||||
|
|
|
@ -24,6 +24,7 @@ extern char gRemoteModsBasePath[];
|
|||
|
||||
void mods_get_main_mod_name(char* destination, u32 maxSize);
|
||||
u16 mods_get_enabled_count(void);
|
||||
u8 mods_has_autoexec_mod(void);
|
||||
bool mods_generate_remote_base_path(void);
|
||||
void mods_activate(struct Mods* mods);
|
||||
void mods_clear(struct Mods* mods);
|
||||
|
|
|
@ -181,9 +181,11 @@ static void coopnet_populate_description(void) {
|
|||
|
||||
// get mod strings
|
||||
if (gActiveMods.entryCount <= 0) { return; }
|
||||
char* strings[gActiveMods.entryCount];
|
||||
char* strings[gActiveMods.entryCount - mods_has_autoexec_mod()];
|
||||
for (int i = 0; i < gActiveMods.entryCount; i++) {
|
||||
strings[i] = gActiveMods.entries[i]->name;
|
||||
struct Mod* mod = gActiveMods.entries[i];
|
||||
if (mod_get_is_autoexec(mod)) { continue; }
|
||||
strings[i] = mod->name;
|
||||
}
|
||||
|
||||
// add seperator
|
||||
|
|
|
@ -51,12 +51,13 @@ void network_send_mod_list(void) {
|
|||
snprintf(version, MAX_VERSION_LENGTH, "%s", get_version());
|
||||
LOG_INFO("sending version: %s", version);
|
||||
packet_write(&p, &version, sizeof(u8) * MAX_VERSION_LENGTH);
|
||||
packet_write(&p, &gActiveMods.entryCount, sizeof(u16));
|
||||
packet_write(&p, &gActiveMods.entryCount - mods_has_autoexec_mod(), sizeof(u16));
|
||||
network_send_to(0, &p);
|
||||
|
||||
LOG_INFO("sent mod list (%u):", gActiveMods.entryCount);
|
||||
for (u16 i = 0; i < gActiveMods.entryCount; i++) {
|
||||
struct Mod* mod = gActiveMods.entries[i];
|
||||
if (mod_get_is_autoexec(mod)) { continue; }
|
||||
|
||||
u16 nameLength = strlen(mod->name);
|
||||
if (nameLength > MOD_NAME_MAX_LENGTH) { nameLength = MOD_NAME_MAX_LENGTH; }
|
||||
|
|
|
@ -264,6 +264,19 @@ void game_exit(void) {
|
|||
exit(0);
|
||||
}
|
||||
|
||||
void enable_autoexec_mod(void) {
|
||||
for (int i = 0; i < gLocalMods.entryCount; i ++) {
|
||||
struct Mod* mod = gLocalMods.entries[i];
|
||||
if (mod_get_is_autoexec(mod)) {
|
||||
#ifdef DEVELOPMENT
|
||||
mod->enabled = true;
|
||||
#else
|
||||
mod->enabled = false;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void* main_game_init(UNUSED void* arg) {
|
||||
const char *gamedir = gCLIOpts.GameDir[0] ? gCLIOpts.GameDir : FS_BASEDIR;
|
||||
const char *userpath = gCLIOpts.SavePath[0] ? gCLIOpts.SavePath : sys_user_path();
|
||||
|
@ -281,6 +294,7 @@ void* main_game_init(UNUSED void* arg) {
|
|||
|
||||
mods_init();
|
||||
enable_queued_mods();
|
||||
enable_autoexec_mod();
|
||||
if (gIsThreaded) {
|
||||
REFRESH_MUTEX(
|
||||
gCurrLoadingSegment.percentage = 0;
|
||||
|
|
Loading…
Reference in New Issue