aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/main.c32
-rw-r--r--src/mod-injector.c81
-rw-r--r--src/mod-loader.def.c22
-rw-r--r--src/mods-example/000_print_a.c21
-rw-r--r--src/mods-example/500_print_b.c28
5 files changed, 184 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
new file mode 100755
index 0000000..b481033
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,32 @@
+/*
+ Copyright (C) 2026 iceyrazor
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <https://www.gnu.org/licenses/>.
+*/
+
+#include "mod-loader.c"
+#include <stdio.h>
+
+#ifndef TEST_FUNC
+#define TEST_FUNC
+void test(char *text){
+ printf("%s\n",text);
+}
+#endif
+
+int main()
+{
+ init_mods();
+ test("insert_text");
+ return 0;
+}
diff --git a/src/mod-injector.c b/src/mod-injector.c
new file mode 100644
index 0000000..849b9e6
--- /dev/null
+++ b/src/mod-injector.c
@@ -0,0 +1,81 @@
+/*
+ Copyright (C) 2026 iceyrazor
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <https://www.gnu.org/licenses/>.
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include <dirent.h>
+
+#define str_size 30000
+
+void str_replace(char* str, char* replace, char* new)
+{
+ char* findstr = strstr(str, replace);
+ if (findstr) {
+ char right[str_size];
+ strncpy(right, &findstr[strlen(replace)], str_size);
+ findstr[0] = '\0';
+ strncat(str, new, str_size);
+ strncat(str, right, str_size);
+ }
+}
+
+int main(int argc, char** argv)
+{
+ // open mod-loader.def.c
+ char buffer[str_size] = { 0 };
+ FILE* mod_loader_file;
+ mod_loader_file = fopen("src/mod-loader.def.c", "r");
+ fread(buffer, str_size, 1, mod_loader_file);
+ fclose(mod_loader_file);
+ buffer[str_size - 1] = '\0';
+
+
+ //look for mods.
+
+ DIR* dir;
+ struct dirent* ent;
+ char include_mods_str[str_size];
+ char init_mods_str[str_size];
+ if ((dir = opendir("src/mods")) != NULL) {
+ /* print all the files and directories within directory */
+ while ((ent = readdir(dir)) != NULL) {
+ if( strcmp(ent->d_name,".") == 0 || strcmp(ent->d_name,"..") == 0 ) continue;
+ strncat(include_mods_str,"#include \"mods/",str_size);
+ strncat(include_mods_str,ent->d_name,str_size);
+ strncat(include_mods_str,"\"\n",str_size);
+
+ char *name=&(ent->d_name[4]);
+ char *name_stripped=strstr(name,".c");
+ name_stripped[0]='\0';
+ strncat(init_mods_str,"init_",str_size);
+ strncat(init_mods_str,name,str_size);
+ strncat(init_mods_str,"();\n",str_size);
+ }
+ closedir(dir);
+ } else {
+ /* could not open directory */
+ perror("");
+ }
+
+ str_replace(buffer, "//<INCLUDE_MODS_REPLACE>", include_mods_str);
+ str_replace(buffer, "//<INIT_MODS_REPLACE>", init_mods_str);
+
+ mod_loader_file=fopen("src/mod-loader.c","w");
+ fwrite(buffer,sizeof(char),strlen(buffer),mod_loader_file);
+ fclose(mod_loader_file);
+
+ return 0;
+}
diff --git a/src/mod-loader.def.c b/src/mod-loader.def.c
new file mode 100644
index 0000000..78711dc
--- /dev/null
+++ b/src/mod-loader.def.c
@@ -0,0 +1,22 @@
+/*
+ Copyright (C) 2026 iceyrazor
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <https://www.gnu.org/licenses/>.
+*/
+
+//<INCLUDE_MODS_REPLACE>
+#include <stdio.h>
+
+void init_mods(){
+//<INIT_MODS_REPLACE>
+}
diff --git a/src/mods-example/000_print_a.c b/src/mods-example/000_print_a.c
new file mode 100644
index 0000000..49cbea8
--- /dev/null
+++ b/src/mods-example/000_print_a.c
@@ -0,0 +1,21 @@
+/*
+ Copyright (C) 2026 iceyrazor
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <https://www.gnu.org/licenses/>.
+*/
+
+#include <stdio.h>
+
+void init_print_a(){
+ printf("PRINTED A\n");
+}
diff --git a/src/mods-example/500_print_b.c b/src/mods-example/500_print_b.c
new file mode 100644
index 0000000..3a3bd79
--- /dev/null
+++ b/src/mods-example/500_print_b.c
@@ -0,0 +1,28 @@
+/*
+ Copyright (C) 2026 iceyrazor
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <https://www.gnu.org/licenses/>.
+*/
+
+#include <stdio.h>
+
+#ifndef TEST_FUNC
+#define TEST_FUNC
+void test(char *text){
+ printf("I DONT WANNA\n");
+}
+#endif
+
+void init_print_b(){
+ printf("PRINTED B\n");
+}