Skip to content

Commit

Permalink
flag.h
Browse files Browse the repository at this point in the history
  • Loading branch information
Ciremun committed Jan 24, 2024
1 parent 191c1a6 commit e5d5873
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 57 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ It doesn't function as an external, [features](#features) will not work.

| Flag | Description |
|:-----------:|:-----------------------------:|
| all | Build All |
| No Flags | Freedom Only |
| standalone | Standalone Only |
| run | Run standalone after build |
| rebuild | Update headers / Rebuild all |
| debug | Symbols, Disable Optimizations|
| | Freedom only |
| rebuild | update headers / rebuild all |
| debug | symbols, disable optimizations|
| console | print logs to console |
| inject | run injector after build |
| all | build standalone and internal |
| standalone | build standlone only |
| run | run standalone after build |
8 changes: 5 additions & 3 deletions freedom/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,14 +456,12 @@ void update_ui()
ImGui::EndCombo();
}

ImGui::Dummy(ImVec2(.0f, 5.f));
ImGui::Dummy(ImVec2(.0f, 10.f));

static bool nt_user_send_input_patched = true;
if (ImGui::Checkbox("Disable NtUserSendInput Check", &nt_user_send_input_patched))
nt_user_send_input_patched ? enable_nt_user_send_input_patch() : disable_nt_user_send_input_patch();
ImGui::Dummy(ImVec2(.0f, 5.f));
if (ImGui::Button("Unload DLL"))
unload_dll();
bool all_found = all_code_starts_found();
if (all_found)
ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
Expand All @@ -474,6 +472,10 @@ void update_ui()
}
if (all_found)
ImGui::PopItemFlag();
ImGui::SameLine(.0f, 20.f);
if (ImGui::Button("Unload DLL"))
unload_dll();
ImGui::Dummy(ImVec2(.0f, 5.f));
}
if (selected_tab == MenuTab::About)
{
Expand Down
6 changes: 3 additions & 3 deletions include/baked_utils_dll.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ static const unsigned int utils_dll_data[8704/4] =
{
0x00905a4d, 0x00000003, 0x00000004, 0x0000ffff, 0x000000b8, 0x00000000, 0x00000040, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000080, 0x0eba1f0e, 0xcd09b400, 0x4c01b821, 0x685421cd, 0x70207369, 0x72676f72, 0x63206d61, 0x6f6e6e61,
0x65622074, 0x6e757220, 0x206e6920, 0x20534f44, 0x65646f6d, 0x0a0d0d2e, 0x00000024, 0x00000000, 0x00004550, 0x0003014c, 0x65b028a1, 0x00000000,
0x65622074, 0x6e757220, 0x206e6920, 0x20534f44, 0x65646f6d, 0x0a0d0d2e, 0x00000024, 0x00000000, 0x00004550, 0x0003014c, 0x65b17c22, 0x00000000,
0x00000000, 0x202200e0, 0x0030010b, 0x00001a00, 0x00000600, 0x00000000, 0x0000394e, 0x00002000, 0x00004000, 0x10000000, 0x00002000, 0x00000200,
0x00000004, 0x00000000, 0x00000004, 0x00000000, 0x00008000, 0x00000200, 0x00000000, 0x85400003, 0x00100000, 0x00001000, 0x00100000, 0x00001000,
0x00000000, 0x00000010, 0x00000000, 0x00000000, 0x000038fc, 0x0000004f, 0x00004000, 0x00000298, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
Expand Down Expand Up @@ -134,8 +134,8 @@ static const unsigned int utils_dll_data[8704/4] =
0x00550066, 0x00420042, 0x00680075, 0x005a0047, 0x00480024, 0x005a0079, 0x004c0030, 0x006e0041, 0x00510066, 0x003d003d, 0x00232f00, 0x007a003d,
0x0024006e, 0x004d004b, 0x004f0038, 0x00420050, 0x00560033, 0x00330044, 0x00450045, 0x00680051, 0x00410058, 0x003d003d, 0x00231700, 0x007a003d,
0x005f0072, 0x0035005f, 0x00300054, 0x003d006f, 0x00233f00, 0x007a003d, 0x00300045, 0x00440056, 0x0066005a, 0x004a0077, 0x00480045, 0x007a0033,
0x00440036, 0x00580033, 0x00710047, 0x0054006d, 0x0044006b, 0x00460052, 0x0077006b, 0x00470066, 0x00000100, 0x7f58ee71, 0x4a83ae27, 0xc88490a8,
0x60d00786, 0x01200400, 0x20030801, 0x20050100, 0x11110101, 0x01012005, 0x07041d11, 0x04311101, 0x59120000, 0x12012005, 0x20050e35, 0x0e391201,
0x00440036, 0x00580033, 0x00710047, 0x0054006d, 0x0044006b, 0x00460052, 0x0077006b, 0x00470066, 0x00000100, 0x15042875, 0x479be248, 0x5c837885,
0x77c4320b, 0x01200400, 0x20030801, 0x20050100, 0x11110101, 0x01012005, 0x07041d11, 0x04311101, 0x59120000, 0x12012005, 0x20050e35, 0x0e391201,
0x11002004, 0x00200331, 0x01000418, 0x07061808, 0x112d1102, 0x1215072d, 0x110e0229, 0x0120052d, 0x06001302, 0x01130120, 0x00050013, 0x08181802,
0x11020007, 0x65111c2d, 0x01022007, 0x01130013, 0x11010704, 0x0307082d, 0x0824111d, 0x20032411, 0x20030e00, 0x070e0800, 0x113d1106, 0x113d113d,
0x41121d3d, 0x00200408, 0x20043d11, 0x04511100, 0x35120020, 0x02020007, 0x35123512, 0x1d002005, 0x07154112, 0x121d080a, 0x35120835, 0x0839121d,
Expand Down
97 changes: 52 additions & 45 deletions nobuild.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@

#define PROCESSES_CAPACITY 256

#define OBJS_FOR_DIRS(objs, body, ...) \
do \
{ \
Cstr_Array objs = cstr_array_make(NULL); \
const char *dirs[] = {__VA_ARGS__}; \
for (size_t i = 0; i < _countof(dirs); ++i) \
{ \
FOREACH_FILE_IN_DIR(file, dirs[i], \
{ \
if (ENDS_WITH(file, ".cpp")) \
objs = cstr_array_append(objs, CONCAT(NOEXT(file), ".obj")); \
}); \
} \
body; \
#define OBJS_FOR_DIRS(objs, body, ...) \
do \
{ \
Cstr_Array objs = cstr_array_make(NULL); \
const char *dirs[] = {__VA_ARGS__}; \
for (size_t i = 0; i < _countof(dirs); ++i) \
{ \
FOREACH_FILE_IN_DIR(file, dirs[i], \
{ \
if (ENDS_WITH(file, ".cpp")) \
objs = cstr_array_append(objs, CONCAT(NOEXT(file), ".obj")); \
}); \
} \
body; \
} while (0)

#define CALL_LINK(objs, ...) \
Expand All @@ -45,11 +45,14 @@
cmd_run_sync(cmd); \
} while (0)

int debug_flag = 0;
int rebuild_flag = 0;
int run_flag = 0;
int standalone_flag = 0;
int all_flag = 0;
int *standalone_flag = 0;
int *debug_flag = 0;
int *rebuild_flag = 0;
int *run_flag = 0;
int *all_flag = 0;
int *console_flag = 0;
int *inject_flag = 0;

char define_commit_hash[32] = {0};

static void remove_object_files()
Expand All @@ -69,13 +72,14 @@ static void async_obj_foreach_file_in_dir(Pid *proc, size_t *proc_count, Cstr di
Cstr src = CONCAT(directory, strdup(file));
Cstr obj = CONCAT(NOEXT(file), ".obj");
if (!PATH_EXISTS(obj) ||
(rebuild_flag || is_path1_modified_after_path2(src, obj)))
(*rebuild_flag || is_path1_modified_after_path2(src, obj)))
{
Cstr_Array line;
Cstr_Array line = *debug_flag ? cstr_array_make("cl", MSVC_DEBUG_FLAGS, src, "/c", NULL) :
cstr_array_make("cl", MSVC_RELEASE_FLAGS, src, "/c", NULL);
if (define_commit_hash[0] != '\0')
line = debug_flag ? cstr_array_make("cl", define_commit_hash, MSVC_DEBUG_FLAGS, src, "/c", NULL) : cstr_array_make("cl", define_commit_hash, MSVC_RELEASE_FLAGS, src, "/c", NULL);
else
line = debug_flag ? cstr_array_make("cl", MSVC_DEBUG_FLAGS, src, "/c", NULL) : cstr_array_make("cl", MSVC_RELEASE_FLAGS, src, "/c", NULL);
line = cstr_array_append(line, define_commit_hash);
if (*console_flag)
line = cstr_array_append(line, "/DFR_LOG_TO_CONSOLE");
Cmd cmd = {.line = line};
INFO("CMD: %s", cmd_show(cmd));
proc[(*proc_count)++] = cmd_run_async(cmd, NULL, NULL);
Expand Down Expand Up @@ -107,7 +111,7 @@ static void build_standalone()
async_obj_foreach_file_in_dirs(STANDALONE_DIRS, NULL);
OBJS_FOR_DIRS(
objs, {
if (debug_flag)
if (*debug_flag)
{
CALL_LINK(objs, "LINK", "/OUT:freedom_standalone.exe", "vendor/GLFW/lib-vc2022/glfw3_mt.lib", "/ENTRY:mainCRTStartup", "/SUBSYSTEM:console", MSVC_LINK_DEBUG_FLAGS);
}
Expand Down Expand Up @@ -176,15 +180,15 @@ static inline void set_git_commit_hash()

static void build_freedom_dll()
{
if (!PATH_EXISTS("utils.dll") || rebuild_flag || is_path1_modified_after_path2("freedom/utils.cs", "utils.dll"))
if (!PATH_EXISTS("utils.dll") || *rebuild_flag || is_path1_modified_after_path2("freedom/utils.cs", "utils.dll"))
{
CMD("csc", "/nologo", "/optimize", "/target:library", "/out:utils.dll", "freedom/utils.cs");
bake_utils_dll();
}
async_obj_foreach_file_in_dirs(DLL_DIRS, NULL);
OBJS_FOR_DIRS(
objs, {
if (debug_flag)
if (*debug_flag)
{
CALL_LINK(objs, "LINK", "/DLL", "/OUT:freedom.dll", MSVC_LINK_DEBUG_FLAGS);
}
Expand All @@ -194,7 +198,7 @@ static void build_freedom_dll()
}
},
DLL_DIRS);
if (!PATH_EXISTS("freedom_injector.exe") || rebuild_flag || is_path1_modified_after_path2("injector.cpp", "freedom_injector.exe"))
if (!PATH_EXISTS("freedom_injector.exe") || *rebuild_flag || is_path1_modified_after_path2("injector.cpp", "freedom_injector.exe"))
{
CMD("cl", "/DWIN32_LEAN_AND_MEAN", "/DNDEBUG", "/DUNICODE", "/std:c++latest", "/MT", "/O2", "/EHsc", "/nologo", "/Fe:freedom_injector.exe", "injector.cpp", "/link", "/MACHINE:x86");
}
Expand All @@ -203,18 +207,23 @@ static void build_freedom_dll()
static void build()
{
set_git_commit_hash();
if (all_flag)
if (*all_flag)
{
build_freedom_dll();
build_standalone();
return;
}
if (standalone_flag)
if (*standalone_flag)
build_standalone();
else
build_freedom_dll();
}

static void inject()
{
CMD(".\\freedom_injector.exe");
}

static void run()
{
CMD(".\\freedom_standalone.exe");
Expand All @@ -227,23 +236,21 @@ static void process_args(int argc, char **argv)
if (PATH_EXISTS(CONCAT(NOEXT(argv[0]), ".obj")))
RM(CONCAT(NOEXT(argv[0]), ".obj"));

for (int i = 0; i < argc; ++i)
{
if (!standalone_flag && strcmp(argv[i], "standalone") == 0)
standalone_flag = 1;
if (!debug_flag && strcmp(argv[i], "debug") == 0)
debug_flag = 1;
if (!rebuild_flag && strcmp(argv[i], "rebuild") == 0)
rebuild_flag = 1;
if (!run_flag && strcmp(argv[i], "run") == 0)
run_flag = 1;
if (!all_flag && strcmp(argv[i], "all") == 0)
all_flag = 1;
}
if (rebuild_flag)
standalone_flag = flag_int("standalone");
debug_flag = flag_int("debug");
rebuild_flag = flag_int("rebuild");
run_flag = flag_int("run");
all_flag = flag_int("all");
console_flag = flag_int("console");
inject_flag = flag_int("inject");
parse_flags(argc, argv);

if (*rebuild_flag)
remove_object_files();
build();
if (run_flag)
if (*inject_flag)
inject();
if (*run_flag)
run();
}

Expand Down
Binary file modified nobuild.exe
Binary file not shown.
55 changes: 55 additions & 0 deletions nobuild.h
Original file line number Diff line number Diff line change
Expand Up @@ -2014,4 +2014,59 @@ stb_uint stb_compress(stb_uchar *out, stb_uchar *input, stb_uint length)
return (stb_uint)(stb__out - out);
}

// NOTE(Ciremun): flag.h
#define FLAGS_CAP 256

typedef struct
{
char *name;
int exists;
} Flag;

typedef struct
{
Flag flags[FLAGS_CAP];
size_t flags_count;
} Flag_Context;

Flag_Context flags_ctx = {0};

static int *flag_int(const char *name)
{
Flag_Context *c = &flags_ctx;
Flag *flag = &c->flags[c->flags_count++];
memset(flag, 0, sizeof(*flag));
flag->name = (char*)name;
return &flag->exists;
}

static char *flag_shift_args(int *argc, char ***argv)
{
assert(*argc > 0);
char *result = **argv;
*argv += 1;
*argc -= 1;
return result;
}

static void parse_flags(int argc, char **argv)
{
Flag_Context *c = &flags_ctx;

flag_shift_args(&argc, &argv);

while (argc > 0) {
char *flag = flag_shift_args(&argc, &argv);
int found = 0;
for (size_t i = 0; i < c->flags_count; ++i) {
if (strcmp(c->flags[i].name, flag) == 0) {
c->flags[i].exists = 1;
found = 1;
}
}
if (!found)
WARN("unknown flag '%s'", flag);
}
}

#endif // NOBUILD_IMPLEMENTATION

0 comments on commit e5d5873

Please sign in to comment.