emerladCoder / RPG-Maker-MV-Cheat-Menu-Plugin

RPG Maker MV Cheat Menu Plugin
348 stars 80 forks source link

Shell script patcher for unixes #8

Open duarm opened 1 year ago

duarm commented 1 year ago

Simple shell script which patches the www/js/plugins.js. requires perl

#!/bin/sh

perl -i~ -0777 -pe 's/var \$plugins =[^{]+/var \$plugins = [\n{"name":"Cheat_Menu","status":true,"description":"","parameters":{}},\n/g' www/js/plugins.js

Step by step

  1. create a patcher.sh file at the root of the game (alongside www/)
  2. paste the above code
  3. make it executable chmod +x patcher.sh
  4. run it.
NamelessMagician commented 1 year ago

Why are you using perl instead of standard Bash? there has to be an easier way to do that. also, from what I can tell this adds the cheat plugin at the beginning of the array. You should ideally be adding it at the end of the array.

duarm commented 1 year ago

Why are you using perl instead of standard Bash? there has to be an easier way to do that.

I knew how to do it with perl, you can do it with pure sed, doesn't really matter.

You should ideally be adding it at the end of the array.

didn't know, never had problems tho

NamelessMagician commented 1 year ago

didn't know, never had problems tho

Problems are pretty rare, but I have seen a few cases where games are very sensitive to load order, thus requiring the cheat plugin to load last.

The only real issue I see with using perl, is that now you're relying on people actually having perl, which while very common, is not on every system out there. Granted, sed may face the same issue. I may look at rebuilding the entire patcher in a way that will allow me to build it for all operating systems.

jSQrD-dev commented 1 year ago

Here's a version that detects the presence of a www/ or js/

#!/bin/sh

if [ -d "www/js" ]
then echo "www directory found | RPG MAKER MV MODE" && perl -i~ -0777 -pe 's/var \$plugins =[^{]+/var \$plugins = [\n{"name":"Cheat_Menu","status":true,"description":"","parameters":{}},\n/g' www/js/plugins.js
fi

if [ -d "js" ]
then echo "js directory found | RPG MAKER MX MODE" && perl -i~ -0777 -pe 's/var \$plugins =[^{]+/var \$plugins = [\n{"name":"Cheat_Menu","status":true,"description":"","parameters":{}},\n/g' js/plugins.js
fi

This can be expanded as need as well. I'll look into converting the perl commands to sed commands and changing where it's appended.

EDIT: Here's the new script

#!/bin/sh

if [ `id -u` = 0 ]
then
        echo "Please run without root perms" && exit
fi

if [ -d "www/js" ]
then echo "www directory found | RPG MAKER MV MODE" && cp www/js/plugins.js www/js/plugins.js~ && sed -i '/];/i ,{"name":"Cheat_Menu","status":true,"description":"","parameters":{}}' www/js/plugins.js
fi

if [ -d "js" ]
then echo "js directory found | RPG MAKER MX MODE" && cp js/plugins.js js/plugins.js~ && sed -i '/];/i,{"name":"Cheat_Menu","status":true,"description":"","parameters":{}}' js/plugins.js
fi

exit

Probably can be simplified

duarm commented 1 year ago

Probably can be simplified

#!/bin/sh

[ "$(id -u)" = 0 ] && echo "Please run without root perms" && exit

PATTERN='/];/i ,{"name":"Cheat_Menu","status":true,"description":"","parameters":{}}'
[ -d "www/js" ] && 
    echo "www directory found | RPG MAKER MV MODE" &&
    cp www/js/plugins.js www/js/plugins.js~ && 
    sed -i "$PATTERN" www/js/plugins.js && 
    exit
[ -d "js" ] && echo "js directory found | RPG MAKER MX MODE" && 
    cp js/plugins.js js/plugins.js~ && 
    sed -i "$PATTERN" js/plugins.js && 
    exit
NamelessMagician commented 1 year ago

Looks nice. You mind if I include it in my next release build on my fork?

duarm commented 1 year ago

Of course, you should, here's a new version I think it's better

#!/bin/sh

[ "$(id -u)" = 0 ] && echo "Please run without root perms" && exit

PATTERN='/];/i ,{"name":"Cheat_Menu","status":true,"description":"","parameters":{}}'
if [ -f "www/js/plugins.js" ]; then
    cp -v www/js/plugins.js www/js/plugins.js~ 2>/dev/null &&
        sed -i "$PATTERN" www/js/plugins.js
elif [ -f "js/plugins.js" ]; then
    cp -v js/plugins.js js/plugins.js~ 2>/dev/null &&
        sed -i "$PATTERN" js/plugins.js
fi

converted to an elif, so we can remove the exits, cp -v notifies the copy, so no need for the echo, we also silence errors with 2>/dev/null, it might happen if you run the script multiple times and backup already exists, or if there's a www/js folder but no plugins.js

NamelessMagician commented 1 year ago

couldn't you avoid that last one using

if [ -f "www/js/plugins.js" ]; then
// code here

Locate the file instead of the directory?

NamelessMagician commented 1 year ago

I went ahead and put it together in a pull request #10.