Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

8 years ago by Joncom

Some games are written in a way that obfuscates very well. An example of such a game would be Agar. You can see the game client code here.

Even if you use jsbeautifier to format the code nicely, it's quite challenging to make sense of anything.

Impact games, when obfuscated using YUI compressor, or an online tool like this one, seem to still be mostly readable.

Why does Agar obfuscate so much better?

8 years ago by AndrewMast

Does this work? (I used my game.min.js and it looked pretty unreadable)

It uses eval, so I wonder if it slows down the game...

-Andrew

8 years ago by AndrewMast

Maybe this?

Please tell me which works best.

-Andrew

8 years ago by Joncom

Thanks for the reply AndrewMast.

Your one suggestion (http://www.danstools.com/javascript-obfuscate/index.php) does a good job at making the code unreadable, however:

1) The process is reversible, so the code being obscured can be made fully readable again with a little work.

2) It seems to break my game and I get this error message:
Uncaught SyntaxError: Unexpected token ILLEGAL
Your other suggestion (http://esprima.org/demo/minify.html), with all the options checked, results in obfuscated code that looks like this:

/><br />
<br />
As we can see, the <code>ig.Font</code> module is still quite clearly defined, and all its pre-obfuscated property and function names remain. The same is true for basically the entire game.<br />
<br />
It would be ideal if the global <code>ig</code> variable was renamed to some arbitrary letter, and everything under it was too.<br />
<br />
An example...<br />
<br />
<code>ig</code> becomes <code>a</code><br />
<code>ig.Font</code> becomes <code>a.b</code><br />
<code>ig.Input</code> becomes <code>a.c</code><br />
<code>ig.Entity</code> becomes <code>a.d</code><br />
etc.			</div>
		</div>
			<div class=

8 years ago by lTyl

It looks like Agar is using the ADVANCED_OPTIMIZATIONS setting in Google Closure Compiler:

Normal:

function unusedFunction(note) {
  alert(note['text']);
}

function displayNoteTitle(note) {
  alert(note['title']);
}

var flowerNote = {};
flowerNote['title'] = "Flowers";
displayNoteTitle(flowerNote);

SIMPLE_OPTIMIZATIONS in Google Closure Compiler:
function unusedFunction(a){alert(a.text)}function displayNoteTitle(a){alert(a.title)}var flowerNote={};flowerNote.title="Flowers";displayNoteTitle(flowerNote);

ADVANCED_OPTIMIZATIONS with Google Closure Compiler:
var a={};a.title="Flowers";alert(a.title);

Here is an example of the method I use:
http://labs.tderen.com/javascript/bundles/

I want to reduce the amount of HTTP requests instead of having code obfuscation. As such, this method lets me bundle all of the assets of a level from source files to media files (Or even the entire game!) into a single file. Then we use our loader, which in this case is our game.min.js file that appears in "View Page Source...". Interestingly enough, this method prevents any game or Impact source from being visible in the View page Source option.

8 years ago by Joncom

Quote from lTyl
It looks like Agar is using the ADVANCED_OPTIMIZATIONS setting in Google Closure Compiler
Looks that way! Thank you. Going to play with this...

8 years ago by AndrewMast

Quote from Joncom
Looks that way! Thank you. Going to play with this...


Have you made your code unreadable? Please post any successes you have. I tried it with the Google Closure Complier, but I kept getting errors when linking the the compiled code with my index.html

-Andrew

8 years ago by Joncom

So far I've managed to get it working on a fresh copy of Impact via this patch:

diff --git a/lib/impact/game.js b/lib/impact/game.js
index 29f3cea..9c3d24f 100644
--- a/lib/impact/game.js
+++ b/lib/impact/game.js
@@ -186,7 +186,7 @@ ig.Game = ig.Class.extend({
 		// remove all killed entities
 		for( var i = 0; i < this._deferredKill.length; i++ ) {
 			this._deferredKill[i].erase();
-			this.entities.erase( this._deferredKill[i] );
+			this.entities['erase']( this._deferredKill[i] );
 		}
 		this._deferredKill = [];
 
diff --git a/lib/impact/impact.js b/lib/impact/impact.js
index e65346a..f6ea29b 100644
--- a/lib/impact/impact.js
+++ b/lib/impact/impact.js
@@ -415,6 +415,9 @@ window.ig = {
 	}
 };
 
+// Fix closure compiler not renaming `ig` properly
+var ig = window.ig;
+
 
 // -----------------------------------------------------------------------------
 // Provide ig.setAnimation and ig.clearAnimation as a compatible way to use
@@ -559,6 +562,9 @@ if( window.ImpactMixin ) {
 })(window);
 
 
+// Fix closure compiler not renaming `ig` properly
+var ig = window.ig;
+
 
 // -----------------------------------------------------------------------------
 // The main() function creates the system, input, sound and game objects,
diff --git a/lib/impact/loader.js b/lib/impact/loader.js
index b792ddd..3c90e26 100644
--- a/lib/impact/loader.js
+++ b/lib/impact/loader.js
@@ -85,7 +85,7 @@ ig.Loader = ig.Class.extend({
 
 	_loadCallback: function( path, status ) {
 		if( status ) {
-			this._unloaded.erase( path );
+			this._unloaded['erase']( path );
 		}
 		else {
 			throw( 'Failed to load resource: ' + path );
diff --git a/lib/impact/sound.js b/lib/impact/sound.js
index 2d12e77..548baf4 100644
--- a/lib/impact/sound.js
+++ b/lib/impact/sound.js
@@ -464,7 +464,7 @@ ig.Sound.WebAudioSource = ig.Class.extend({
 		// later when it has finished playing.
 		var that = this;
 		this.sources.push(source);
-		source.onended = function(){ that.sources.erase(source); }
+		source.onended = function(){ that.sources['erase'](source); }
 
 		source.start(0);
 	},

Edit: Most things obfuscated nicely, but a few things didn't. Not sure why yet...

8 years ago by AndrewMast

Thanks! I will try it out

Is there a way to request Dominic to add that?

-Andrew
Page 1 of 1
« first « previous next › last »