pairofdocs / gomule-d2r

GoMule enabled for D2R
GNU Affero General Public License v3.0
59 stars 16 forks source link

d2r holds saves when open #6

Open Pwntheon opened 2 years ago

Pwntheon commented 2 years ago

Hi.

It appears you need to quit d2r completely to mule - you can't just leave the game. If you have the game open, this can lead to items disappearing (if you move from stash to char) or duping (char to stash).

In the long run it would be nice to add some checks to see if the file has actually been written to, but short term, maybe check if d2r is open and give a warning or something?

pairofdocs commented 2 years ago

Hey, good point

The main menu displays character's gear and D2R keeps the save file open. (EDIT: keeps the char data in memory)

I want to stay away from checking memory for open processes since Windows will give virus warnings for Gomule. I'll add a warning to the app to exit D2R when using Gomule and also to the Readme Doc)

I'll think about how to add a code check to prevent accidental saving when D2R is open. Maybe have a pop-up confirmation window but that could be annoying to click through every time saving happens

Pwntheon commented 2 years ago

I do believe that a simple FileUtils.touch(savefile) (Apache Commons IO) will throw an IOException if the file is open (i.e. d2r is holding it).

Maybe check this before performing actions on a save file?

I agree in general that a modal window is annoying in general. However, since this is a potentially destructive action, it's justified in my view.

m4ke72 commented 2 years ago

File cannot be open if you can save over it? I think D2R caches chars and saves them at exit.

m4ke

pairofdocs commented 2 years ago

@Pwntheon good idea

Trying this example from stack overflow https://stackoverflow.com/questions/1390592/check-if-file-is-already-open

Like m4ke72 said D2R keeps the char data in memory and writes to the savefile once the game is closed

I think your first suggestion is the way to go-- checking for a running process Game.exe / D2R.exe.

                        String processName = "D2R.exe"; 
            ProcessBuilder processBuilder = new ProcessBuilder("tasklist.exe");
            try {
                Process process = processBuilder.start();
                Scanner scanner = new Scanner(process.getInputStream(), "UTF-8").useDelimiter("\\A");
                String strr = scanner.hasNext() ? scanner.next() : "";
                System.err.println("process scanner: " + strr);
                scanner.close();

                                // check if game is running
                System.err.println("strr.contains(processName);: " + strr.contains(processName));
            }catch(Exception e) {
                ;
            }

this check from stack overflow is working, i'll see if Windows has any "potential unsafe software" warnings when opening the gomule.jar

m4ke72 commented 2 years ago

Please don't make this Win only software !

m4ke

pairofdocs commented 2 years ago

@m4ke72 Good point, I realized that just now when testing

pairofdocs commented 2 years ago

@Pwntheon here's a build ready with a check for d2r.exe running before saving files https://github.com/pairofdocs/gomule-d2r/archive/refs/heads/main.zip

I didn't get any annoying windows warning popups when launching gomule.jar