Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1] 2 3 ... 9
1  Discussions / General Discussions / Re: So you thought Java strings were immutable? on: 2014-02-17 20:24:50
heres one for .net:

1  
typeof(string).GetField("Empty").SetValue(null, " ");


Yep taken from TDWTF

with C++ you can have even more fun:

1  
2  
3  
4  
5  
6  
7  
8  
9  
#define if(X) if (float(rand())/float(RAND_MAX) > 0.01f && (X))
#ifdef TRUE
#undef TRUE
#endif
#ifdef FALSE
#undef FALSE
#endif
#define TRUE 0
#define FALSE 1
2  Discussions / General Discussions / Re: So you thought Java strings were immutable? on: 2014-02-17 20:21:01
... or wreck havoc in otherwise mundane JEE applications where boxing/unboxing is common:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
Integer instance = Integer.valueOf(63);
Field field = instance.getClass().getDeclaredField("value");
field.setAccessible(true);
field.set(instance, Integer.valueOf(62));


public int addOne(Integer value){
   return value + 1;
}

addOne(63) == 63;


remember this only works when the number is -127 to 128 though Wink
3  Discussions / General Discussions / Re: So you thought Java strings were immutable? on: 2014-02-17 20:15:28
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
public class Lol {

    static class Lololol extends Thread {

        public void run() {
            while (true) {
                rofl();
                try {
                    sleep(1000);
                } catch (Throwable t) {
                }
            }
        }

        public void rofl() {
            try {
                Field field = Integer.class.getDeclaredField("value");
                field.setAccessible(true);
                for (int i = -127; i <= 128; i++) {
                    field.setInt(
                            Integer.valueOf(i),
                            Math.random() < 0.5 ? -i : i);
                }
            } catch (Throwable t) {;
            }
        }

    }

    static void lol(Field field, Object newValue) throws Exception {
        field.setAccessible(true);
        Field modifiersField = Field.class.getDeclaredField("modifiers");
        modifiersField.setAccessible(true);
        modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
        field.set(null, newValue);
    }

    /**
     * @param args the command line arguments
     */

    public static void main(String[] args) throws Throwable {
        lol(Boolean.class.getField("FALSE"), true);
        boolean lol = Boolean.FALSE;
        System.out.println("lol: " + lol);
        new Lololol().start();

        Field field = Integer.class.getDeclaredField("value");
        field.setAccessible(true);
        field.setInt(Integer.valueOf(0), 1337);
        System.out.println((Integer) 0);

        for (;;) {
            Integer i1 = 1;
            Integer i2 = 2;

            System.out.println(i1 + i2);

            Thread.sleep(1000);
        }
    }

}


imagine putting this in some big application
4  Discussions / General Discussions / Re: So you thought Java strings were immutable? on: 2014-02-17 20:08:57
Yes, with reflection and similar tricks no class is immutable, keep in mind though that the hashcode is cached upon first calculating it. Iirc, String's hashcode caching is removed in the more recent jdk7:s (that, or I dreamt it).

you can hack the hashCode as well by using reflection.
5  Discussions / General Discussions / So you thought Java strings were immutable? on: 2014-02-17 19:20:34
I was messing around with a bit of Java recently, and I just discovered that java.lang.String is in fact not 100% immutable

consider:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
public class HelloWorld {

    public static void append(String s1, String s2) {
        try {
            Field value = String.class.getDeclaredField("value");
            value.setAccessible(true);
            value.set(s1, s2.toCharArray());
            Field count = String.class.getDeclaredField("count");
            count.setAccessible(true);
            count.set(s1, s2.length());
        } catch (Exception ex) {
        }
    }

    public static final String MESSAGE = "Hello world!";

    static {
        append(MESSAGE, "Lol goodbye");
    }

    /**
     * @param args the command line arguments
     */

    public static void main(String[] args) {
        System.out.println(MESSAGE);
    }

}
6  Games Center / Android Showcase / Re: Dragon Run [NOW ON GOOGLE PLAY & APPLE APP STORE] on: 2014-02-16 07:57:43
After 10 long agonizing minutes, I managed to do this somehow :O


Haha that's actually not bad!
7  Games Center / Android Showcase / Re: Dragon Run [NOW ON GOOGLE PLAY & APPLE APP STORE] on: 2014-02-15 19:59:20
I find this impossible to play.. The moment you see next pillar, it is already to late, because acceleration is too extreme. It is very slow at start, and very fast when it picks up. Maybe its just because I'm bad at this game Cheesy

Haha, its not impossible it just takes skill Smiley

It speeds up as you get a better and better score. (there is a limit though, and this game is always possible, no matter what score you get - it won't suddenly go to a point where the acceleration is too high it makes it impossible)
8  Games Center / Android Showcase / Re: Dragon Run [NOW ON GOOGLE PLAY & APPLE APP STORE] on: 2014-02-15 19:56:26
Maybe I'm just being picky, though shouldn't the highest score change when you beat your previous highest score?

Took me 30 minutes to get that...  Clueless

By the way, I love the title of the webpage. Cheesy

It does update the best, but it doesn't display it until the next death Smiley

And ahaha, oops Tongue
9  Games Center / Android Showcase / Re: Dragon Run [NOW ON GOOGLE PLAY & APPLE APP STORE] on: 2014-02-15 18:24:22
Desktop version available at http://ux-soft.com/dragonrun
10  Games Center / Android Showcase / Re: Dragon Run [NOW ON GOOGLE PLAY & APPLE APP STORE] on: 2014-02-15 17:39:08
We're on iOS now!

https://itunes.apple.com/us/app/dragon-run!/id817359916?ls=1&mt=8

Please can a mod move this to Showcase?
11  Java Game APIs & Engines / Engines, Libraries and Tools / Re: LWJGL Orthographic Sidescroller Camera on: 2014-02-14 11:31:15
where did you put the translate code?
12  Java Game APIs & Engines / Engines, Libraries and Tools / Re: LWJGL Orthographic Sidescroller Camera on: 2014-02-14 11:13:52
You don't have the variables player and vp defined. Make a player class with member variable floats x, y and make a viewport class with member variable floats width and height.

Also your logic slows down the player when they press the keys. Shouldn't you be speeding him up?
13  Java Game APIs & Engines / Engines, Libraries and Tools / Re: LWJGL Orthographic Sidescroller Camera on: 2014-02-14 11:09:30
Just translate everything to player.x - viewport.width/2, player.y - viewport.height/2, example:

1  
glTranslatef(player.x - vp.width/2, player.y - vp.height/2, 0);
14  Games Center / WIP games, tools & toy projects / Re: Invasion on: 2014-02-13 18:37:25
I didnt get how to play the game, and once I exited, my mouse speed was set to 200% and my capslock was toggled on, what?

Good attempt at a first game though Smiley
15  Games Center / WIP games, tools & toy projects / Re: Renoria - Java MMORPG on: 2014-02-12 05:25:52
We're now on IndieDB, watch us, comment, or whatever, support us! Smiley

16  Game Development / Shared Code / Re: ProtectedInteger - Protect your game from memory editors on: 2014-02-11 17:08:23
Don't use java.util.Random.  Use a custom generator or ThreadLocalRandom.  A simple custom generator inside the class would reasonable.

ThreadLocalRandom is JRE7 only. Random is probably the easiest, and your custom generator is just as prone to being hacked (patching currentTimeMillis) but anyway I did this just for completeness sake:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
public final static class ProtectedInteger {

        private int value;
        private int key;
        private static long x = System.currentTimeMillis();

        private static int rnd() {
            x ^= (x << 21);
            x ^= (x >>> 35);
            x ^= (x << 4);
            int a = (int)x;
            int b = (int)(x << 16);
            return a^b;
        }

        public ProtectedInteger(int x) {
            set(x);
        }

        public int get() {
            return (~value) ^ key;
        }

        public void set(int value) {
            key = rnd();
            this.value = (~value) ^ key;
        }

        public void increment() {
            set(get() + 1);
        }

        public void decrement() {
            set(get() - 1);
        }

        public void add(int x) {
            set(get() + x);
        }

        public void dec(int x) {
            set(get() - x);
        }
    }
17  Game Development / Shared Code / Re: ProtectedInteger - Protect your game from memory editors on: 2014-02-11 16:23:53
Sorry, I know nothing about memory editors, but why couldn't someone read both the key and value and do the bitwise operations themselves?

Most people cheat in games by scanning for known values, rescanning when they change and locating the memory addresses of these values then freezing them to a certain value.

Cheat Engine does this through the WinAPI ReadProcessMemory and WriteProcessMemory which scans your games virtual memory into a buffer, repeatedly compares it to the search value and listing all memory addresses that match.

What this code will do is prevent memory scanners from easily being able to locate the value in memory, thus effectively preventing most noob cheaters from being able to find and modify the value in memory. Its just a thing you can add to prevent noobs from easily hacking your game, but it wont stop determined cheaters, they have full control over the system and can do things like patching java.util.Random, modifying the Java ASM of your binary or even replacing the entire class with something different, just take it as a little thing you can add to stop noobs from getting high on your leaderboards.

I added the bit negation part to make it harder to locate the value if they did something like patch java.util.Random#nextInt to always return 0 for example.
18  Game Development / Shared Code / Re: ProtectedInteger - Protect your game from memory editors on: 2014-02-11 13:57:06
Test case:

1  
2  
3  
4  
5  
6  
7  
8  
    public static void main(String[] args) {
        ProtectedInteger val = new ProtectedInteger(10);

        for (int i = 0; i < 100; i++) {
            System.out.println(val.get() + " " + val.value);
            val.increment();
        }
    }


Outputs:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
run:
10 -386515262
11 74483033
12 -1122491933
13 1118343985
14 762439197
15 -985898577
16 881353416
17 422096154
18 1505261334
19 121576051
20 17291655
21 -96702182
22 966360379
23 -1895779012
24 865142212
25 -1383423927
26 -589614975
27 1189690637
28 1072681489
29 161160089
30 -277172843
31 -302291489
32 -943339751
33 2101492437
34 1659792334
35 -1899310279
36 -1644697812
37 -705545973
38 -2093534530
39 -175402530
40 2057488254
41 -347530170
42 1502839416
43 283446646
44 -950056026
45 -5485854
46 1449997393
47 638291025
48 1349261190
49 -769018597
50 1951975830
51 -95943249
52 922065223
53 1911112935
54 1786356626
55 189190580
56 -1929887166
57 771225551
58 487991180
59 1895992282
60 970346814
61 -136259347
62 190481433
63 -391566216
64 -244039267
65 -1558266925
66 1090033047
67 1949180994
68 -867907562
69 -1447792821
70 -851498719
71 521997521
72 -1361123344
73 99077230
74 1730843655
75 1399665494
76 -918123877
77 -319369290
78 -359374539
79 1095699465
80 -1028016978
81 1566878876
82 1841794486
83 -2014225033
84 1012541623
85 -940605984
86 -1139109650
87 1808573676
88 1697456487
89 1260259679
90 -242734332
91 -1512041962
92 -228034694
93 -513819170
94 1750318446
95 1865684026
96 -1717677497
97 1202705953
98 1146459803
99 -508867389
100 -1395769789
101 -1185984196
102 56068681
103 -1419021223
104 -730578283
105 -1019730625
106 -290345062
107 1102347527
108 -1759749726
109 1915150644
BUILD SUCCESSFUL (total time: 0 seconds)
19  Game Development / Shared Code / ProtectedInteger - Protect your game from memory editors on: 2014-02-11 13:56:17
This code will prevent memory editors from easily being able to scan for a protected value in your game

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
public class ProtectedInteger {

        private int value;
        private int key;
        private static Random RND = new Random();
       
        public ProtectedInteger(int x) {
            set(x);
        }

        public int get() {
            return (~value) ^ key;
        }

        public void set(int value) {
            key = RND.nextInt();
            this.value = (~value) ^ key;
        }

        public void increment() {
            set(get() + 1);
        }

        public void decrement() {
            set(get() - 1);
        }
       
        public void add(int x) {
            set(get() + x);
        }
       
        public void dec(int x) {
            set(get() - x);
        }
    }


version without java.util.Random:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
public final static class ProtectedInteger {

        private int value;
        private int key;
        private static long x = System.currentTimeMillis();

        private static int rnd() {
            x ^= (x << 21);
            x ^= (x >>> 35);
            x ^= (x << 4);
            int a = (int)x;
            int b = (int)(x << 16);
            return a^b;
        }

        public ProtectedInteger(int x) {
            set(x);
        }

        public int get() {
            return (~value) ^ key;
        }

        public void set(int value) {
            key = rnd();
            this.value = (~value) ^ key;
        }

        public void increment() {
            set(get() + 1);
        }

        public void decrement() {
            set(get() - 1);
        }

        public void add(int x) {
            set(get() + x);
        }

        public void dec(int x) {
            set(get() - x);
        }
    }


I know its not foolproof, anyone who knows Java ASM would be able to hack through, or patching the default constructor of Random() or something, but its enough to deter noob cheaters.
20  Games Center / WIP games, tools & toy projects / Re: Renoria - Java MMORPG on: 2014-02-11 05:45:08
Liera Tree is pretty much nearly finished, just gonna show a scaled down version of the map (33%)



Just need to finish placing some vines, place some more NPCs and link it to the rest of the world.
21  Games Center / Android Showcase / Re: Dragon Run [NOW ON GOOGLE PLAY] on: 2014-02-09 10:57:34
Just posted the app to the iOS App Store, awaiting Apple review now.
22  Games Center / Android Showcase / Re: Dragon Run [NOW ON GOOGLE PLAY] on: 2014-02-09 06:30:15
Thanks everyone for the amazing response and reviews!





23  Games Center / Android Showcase / Re: Dragon Run [NOW ON GOOGLE PLAY] on: 2014-02-09 03:50:37
You may be rich (if you sell it). Flappy bird is being taken off the market both on the market itself and its copyright Wink http://www.usatoday.com/story/tech/gaming/2014/02/08/flappy-bird-removed/5315655/

Haha I just made it for fun so yeah Cheesy

Its pretty different to Flappy anyways.
24  Games Center / Android Showcase / Re: Dragon Run [NOW ON GOOGLE PLAY] on: 2014-02-09 02:49:47
Can a mod move this to Showcase?

I'll be releasing the iOS and Desktop versions as soon as Apple finishes the review.
25  Games Center / Android Showcase / Re: Dragon Run [NOW ON GOOGLE PLAY] on: 2014-02-08 16:22:44
GAME HAS BEEN RELEASED ON GOOGLE PLAY!

https://play.google.com/store/apps/details?id=com.uxsoft.dragonrun


iOS & Desktop versions coming soon!
26  Game Development / Newbie & Debugging Questions / Re: Only Clicking Once on: 2014-02-08 15:18:25
Them magic numbers...

Also no shit every time your mouseReleased method is called it will go straight to state 8.

You set menuState to 5 and then check if it's 5 then set it to 8 so it will always be 8.

To fix:

1  
2  
3  
4  
5  
6  
7  
8  
9  
public void mouseReleased(MouseEvent e) {
      if ( e.getButton() == MouseEvent.BUTTON1) {
         if (menuState==1) {menuState = 5;}
         else if (menuState==2) {menuState = 5;}
         else if (menuState==3) {menuState = 5;}
         else if (menuState==4) {menuState = 5;}
         else if (menuState==5) {menuState = 8;}
      }
   }
27  Java Game APIs & Engines / Engines, Libraries and Tools / Re: [libGDX] facebook iOS connectivity on: 2014-02-08 15:15:47
Never mind, found what I need: https://github.com/BlueRiverInteractive/robovm-ios-bindings

I'll leave this here for anyone who might run into the same issue.
28  Java Game APIs & Engines / Engines, Libraries and Tools / [libGDX] facebook iOS connectivity on: 2014-02-08 15:06:51
Does anyone here have any experience or success with Facebook integration via libGDX / RoboVM backend?

I've been trying to figure out how to implement a binding (via Bro?) to native Facebook ObjC API for a while now and I've still got no lead.

Discuss?  Smiley
29  Games Center / Android Showcase / Re: Dragon Run [Inspired by FlappyBirds] on: 2014-02-07 15:01:00
Now has a nice title screen and hiscores system!



30  Games Center / WIP games, tools & toy projects / Re: Renoria - Java MMORPG on: 2014-02-07 00:09:56
Hey! I really love your project and i am checking it out every day.
I am a big MMORPG fan especially 2D MMORPG's.
Can you, please, share some information about how is working your networking? Maybe some samples, if that's not a problem.
I really want to learn a MMORPG networking and gather some useful information for future game developments.
Thank you!

I wish you the best and hope to play Renoria someday.

Hey thanks for the kind words.

Well basically in Renoria we use a 3 byte header per packet.

2 bytes first for the packet length and 1 byte for packet ID. Packet ID can be anything from login to attack to drop item. This header is then hashed with the current IV of the packet encryptor, then the message body is encrypted with AES128, and the IV is updated to the next state. The server now receives this message, it can then update its own IV (as the IV is mirrored on both instances) and then decode the packet with the current IV. If the hash matches, the packet goes through and is processed, otherwise the client is dropped. The hashing algo I use is just a simple bitrotate on the 2 bits of packet length xored with packet id.

For packet handling I just use an array like this:

1  
PacketHandler[] handlers = new PacketHandler[RecvOps.MAX_ID];


and to handle packet:

1  
2  
3  
4  
void handlePacket(Packet p) {
    PacketHandler handler = handlers[p.getPacketID()];
    handler.handle(p.getMessageBody());
}
Pages: [1] 2 3 ... 9
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (37 views)
2014-12-15 09:26:44

Mr.CodeIt (30 views)
2014-12-14 19:50:38

BurntPizza (61 views)
2014-12-09 22:41:13

BurntPizza (98 views)
2014-12-08 04:46:31

JscottyBieshaar (59 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (77 views)
2014-11-29 21:32:03

toopeicgaming1999 (138 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36

toopeicgaming1999 (38 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!