pumpitupdev / pumptools

A collection of tools to run Pump It Up games.
The Unlicense
22 stars 7 forks source link

Microdog40 Standalone Emulator - [merged] #38

Closed voidderef closed 3 years ago

voidderef commented 3 years ago

In GitLab by @Cube on Jan 12, 2021, 03:16

Merges microdog40-emu -> master

Summary

Adds a binary called microdog40d, which allows you to run a standalone microdog40 emulator without hooking the binary.

Description

Added a simple wrapper around the hook to run the daemon with a supplied keyfile

How Has This Been Tested?

Tested using this to run Infinity without the dongle

Checklist

voidderef commented 3 years ago

In GitLab by @Cube on Jan 12, 2021, 15:36

changed the description

voidderef commented 3 years ago

In GitLab by @icex2 on Jan 13, 2021, 20:33

Commented on src/main/sec/microdog40/microdog40.c line 19

I am not sure to what extend this is going to be a conflict, but the commit of this change is already on master. Therefore, you might want to drop it from your MR if that creates a conflict when rebasing and merging.

voidderef commented 3 years ago

In GitLab by @icex2 on Jan 13, 2021, 20:38

Commented on Package.mk line 178

Let's create a new category and call it "security":

# Security: Lexical sorting
voidderef commented 3 years ago

In GitLab by @icex2 on Jan 13, 2021, 20:38

Commented on Package.mk line 180

$(zipdir)/security.zip: \
voidderef commented 3 years ago

In GitLab by @icex2 on Jan 13, 2021, 20:40

Commented on Package.mk line 237

        $(zipdir)/security.zip \
        $(zipdir)/x2hook.zip \

We also need to add the new category zip here that it gets packed into the root distribution zip.

voidderef commented 3 years ago

In GitLab by @icex2 on Jan 13, 2021, 20:40

Commented on Package.mk line 257

        $(zipdir)/security.zip \
        $(zipdir)/x2hook.zip \

Same here.

voidderef commented 3 years ago

In GitLab by @icex2 on Jan 13, 2021, 20:43

Commented on src/main/sec/microdog40/main.c line 26

Nit: Remove one empty line.

voidderef commented 3 years ago

In GitLab by @icex2 on Jan 13, 2021, 20:45

Commented on src/main/sec/microdog40/main.c line 67

I don't see any benefit in running sec_microdog40d_run in a dedicated thread. I would simplify this and just stick the sec_microdog40d_run method in here. The sleep(10) is definitly a good idea to reduce CPU load.

However, it would be nice if the user can also exit the daemon, e.g. by sending a SIGINT to the application (CTRL + C). Do you mind adding that?

voidderef commented 3 years ago

In GitLab by @icex2 on Jan 13, 2021, 20:53

Commented on src/main/sec/microdog40/main.c line 9

I would set the log level to debug using util_log_set_level(LOG_LEVEL_DEBUG); to provide verbose output for debugging things.

Optional: If you want to spend the effort, you can add an argument -v to switch between logging with info level and debug.

voidderef commented 3 years ago

In GitLab by @icex2 on Jan 13, 2021, 20:54

Commented on src/main/sec/microdog40/main.c line 11

    if (argc != 2) {

Nit, style: No spaces after ( and before )

voidderef commented 3 years ago

In GitLab by @icex2 on Jan 13, 2021, 20:58

Commented on src/main/sec/microdog40/main.c line 13

        return 1;
voidderef commented 3 years ago

In GitLab by @icex2 on Jan 13, 2021, 21:02

Commented on src/main/sec/microdog40/main.c line 22

There is actually a convenient helper function for loading binary files in util/file.h: util_file_load

if (argc != 2) {
    ...
    return 1;
}

// Note for review (remove when using code): The else is not required as you early return already above. Improves readability

size_t key_data_len;
uint8_t* key_data;

if (util_file_load(argv[1], &key_data, &key_data_len, false) {
    log_error("Loading key file %s failed", argv[1]);
    return 2;
}

// ... do your loop here

util_xfree(&key_data);
// do more cleanup...
voidderef commented 3 years ago

In GitLab by @icex2 on Jan 13, 2021, 21:05

Commented on src/main/sec/microdog40/main.c line 33

Actually, I forgot that I even created a daemon module for it...makes sense just re-using that here. Please also re-use sec_microdog40d_is_running in the loop. Call sec_microdog40d_shutdown on SIGINT to terminate the loop.

voidderef commented 3 years ago

In GitLab by @Cube on Jan 13, 2021, 21:39

added 1 commit

Compare with previous version

voidderef commented 3 years ago

In GitLab by @Cube on Jan 13, 2021, 21:41

thanks for the comments, ill start cleaning it up

voidderef commented 3 years ago

In GitLab by @Cube on Jan 13, 2021, 22:58

Commented on src/main/sec/microdog40/main.c line 33

I tried adding this, but since sec_microdog40d_is_run_d is checked in a loop that can get blocked waiting on a recvfrom, Testing without actually running a game means, when shutdown is called by the signal, it cannot progress and actually flip sec_microdog40d_is_running to false. Trying to think of a workaround. Probably setting up a timeout with setsockopt is the correct way to handle this.

voidderef commented 3 years ago

In GitLab by @icex2 on Jan 13, 2021, 23:45

Commented on src/main/sec/microdog40/main.c line 33

Didn’t consider this, good point. Making the run function non-blocking with a set timeout sounds like a good idea. Can you check and verify that this also works with the current setup in the hooks, e.g. nx2hook?

voidderef commented 3 years ago

In GitLab by @Cube on Jan 13, 2021, 23:50

Commented on Package.mk line 178

changed this line in version 3 of the diff

voidderef commented 3 years ago

In GitLab by @Cube on Jan 13, 2021, 23:50

Commented on src/main/sec/microdog40/main.c line 26

changed this line in version 3 of the diff

voidderef commented 3 years ago

In GitLab by @Cube on Jan 13, 2021, 23:50

Commented on src/main/sec/microdog40/main.c line 9

changed this line in version 3 of the diff

voidderef commented 3 years ago

In GitLab by @Cube on Jan 13, 2021, 23:50

Commented on src/main/sec/microdog40/main.c line 11

changed this line in version 3 of the diff

voidderef commented 3 years ago

In GitLab by @Cube on Jan 13, 2021, 23:50

Commented on src/main/sec/microdog40/main.c line 13

changed this line in version 3 of the diff

voidderef commented 3 years ago

In GitLab by @Cube on Jan 13, 2021, 23:50

Commented on src/main/sec/microdog40/main.c line 22

changed this line in version 3 of the diff

voidderef commented 3 years ago

In GitLab by @Cube on Jan 13, 2021, 23:50

Commented on src/main/sec/microdog40/main.c line 33

changed this line in version 3 of the diff

voidderef commented 3 years ago

In GitLab by @Cube on Jan 13, 2021, 23:50

added 1 commit

Compare with previous version

voidderef commented 3 years ago

In GitLab by @Cube on Jan 13, 2021, 23:54

Commented on src/main/sec/microdog40/main.c line 33

testing in nx2 right now

voidderef commented 3 years ago

In GitLab by @Cube on Jan 13, 2021, 23:54

Commented on src/main/sec/microdog40/main.c line 33

so issue with nx2 after adding the timeout

voidderef commented 3 years ago

In GitLab by @Cube on Jan 13, 2021, 23:58

added 1 commit

Compare with previous version

voidderef commented 3 years ago

In GitLab by @Cube on Jan 14, 2021, 24:00

added 3 commits

Compare with previous version

voidderef commented 3 years ago

In GitLab by @Cube on Jan 14, 2021, 24:04

added 2 commits

Compare with previous version

voidderef commented 3 years ago

In GitLab by @Cube on Jan 14, 2021, 24:06

added 2 commits

Compare with previous version

voidderef commented 3 years ago

In GitLab by @Cube on Jan 14, 2021, 24:09

Okay! Finally fixed up the commits so it is nice and clean.

Only thing I didn't add was a debug flag for changing the logging. Just looking for a -v option that sets util_log_set_level(LOG_LEVEL_DEBUG) correct?

voidderef commented 3 years ago

In GitLab by @Cube on Jan 14, 2021, 23:20

added 1 commit

Compare with previous version

voidderef commented 3 years ago

In GitLab by @Cube on Jan 14, 2021, 23:21

added the debug option

voidderef commented 3 years ago

In GitLab by @Cube on Jan 14, 2021, 23:21

marked this merge request as ready

voidderef commented 3 years ago

In GitLab by @Cube on Jan 14, 2021, 23:54

Commented on src/main/sec/microdog40/main.c line 9

Added debug option

voidderef commented 3 years ago

In GitLab by @Cube on Jan 14, 2021, 23:54

resolved all threads

voidderef commented 3 years ago

In GitLab by @icex2 on Jan 16, 2021, 15:53

Nice job. There are two or three nits that are rather minor and I let pass to not further block this. Thanks for the contribution.

voidderef commented 3 years ago

In GitLab by @icex2 on Jan 16, 2021, 15:53

approved this merge request