Page 1 of 2 12 LastLast
Results 1 to 25 of 44

Thread: The Java Programming Thread

  1. #1

    Join Date
    05-06-12
    Posts
    1,035
    vCash
    3700

    The Java Programming Thread

    Back on the old forum I wrote some tutorials on Java programming, well now they're back!

    These tutorials aren't going to be for everyone but if you're an IT person you might be surprised how (relatively) easy it is to write software. It will mainly be useful to automate the editing of CM data (including save games).

    Steps involved:

    Download and install this: http://www.oracle.com/technetwork/ja...s-1880260.html (pick the version you need based on your OS)

    Then do likewise with this: http://textpad.com/download/index.html

    Note: you need to do the above in this order because TextPad detects Java during installation - so if you installed TextPad first it won't find your Java installation so it wouldn't work.

    Finally, download this: http://www.sendspace.com/file/rb0leu and extract the contents into a directory - this is a collection of code for editing CM data (written by me) and some are additional libraries of code courtesy of http://commons.apache.org/.

    Now to test if this has worked.

    Open Example.java (included in the above download) in TextPad
    Code:
    public class Example {
    	public static void main(String[] args) throws Exception {
    		System.out.println("ChampMan0102.co.uk - Keeping the game alive!");
    	}
    }
    You can probably guess what this code will do.

    Press Ctrl+1 to 'compile' this code - you should get a message saying 'Tool completed successfully'.

    Now press Ctrl+2 to execute the code - you should then see the above message printed in a command prompt window.
    Last edited by JohnLocke; 01-10-13 at 07:34 PM. Reason: link updated

  2. #2

    Join Date
    18-12-11
    Location
    Dresden
    Posts
    7,502
    vCash
    4030
    i'll have to give this a try again so will probably hassle you with noob questions

  3. #3

    Join Date
    05-06-12
    Posts
    1,035
    vCash
    3700
    One final thing you need to do to configure TextPad is to tell it where to find the code you downloaded. To do this go to Configure > Preferences > Environment Variables and click 'New', enter 'CLASSPATH' in the name field and '.;c:\java\libs\*;' in the value field. You will need to change the location accordingly to reflect wherever you decide to put the libs directory.

  4. #4

    Join Date
    05-06-12
    Posts
    1,035
    vCash
    3700
    Code:
    import core.files.NationFile;
    import core.files.PersonFile;
    import core.obj.map.StaffFinder;
    import core.obj.Person;
    import core.obj.Nation;
    import core.PreData;
    
    public class Messi {
    
    	public static void main(String[] args) throws Exception {
    
    		PreData data = new PreData("C:/Program Files/Championship Manager 01-02/Data/");
    
    		NationFile nations = data.getNations();
    
    		Nation england = nations.findByLongName("England");
    
    		StaffFinder sf = new StaffFinder(data);
    
    		Person messi = sf.findFirst("Lionel Messi");
    
    		messi.setNationality(england);
    
    		data.save();
    
    	}
    
    }
    You can probably tell what this code will do - you might need to change the location of your data to make it work though. Make sure you back it up first!

  5. #5

    Join Date
    17-06-12
    Posts
    331
    vCash
    500
    JL can u tell whatthat error means

    java.io.EOFException: offset=1140850688, sof=0, eof=804360
    Last edited by MarcoVanBast; 09-04-13 at 03:18 PM.

  6. #6

    Join Date
    16-12-11
    Location
    Australia
    Posts
    11,826
    vCash
    0
    Don't delete them. When you make a post just put all the details in there, not 50 different posts. I come in here like many others to see what's progressing and all I see is your problems, just keep them to one post

  7. #7

    Join Date
    05-06-12
    Posts
    1,035
    vCash
    3700

    Mass editing player stats

    This code will cap the positioning attribute to 10 for everyone with a CA of less than 175. You'll obviously want to change the name / location of your save game - and it only works on uncompressed saves. Save the files as 'PositioningFix.java'.

    Code:
    import java.io.File;
    
    import core.SaveData;
    import core.obj.Player;
    import core.files.PlayerFile;
    import core.files.PlayerAttribute;
    
    public class PositioningFix {
    
    	public static void main(String[] args) throws Exception {
    
    		File sav = new File("C:/Program Files/Championship Manager 01-02/Norway.sav");
    		SaveData data = new SaveData(sav);
    		PlayerFile players = data.getPlayers();
    
    		int count = 0;
    
    		final int MAX_POS = 10;
    
    		for(Player pl : players) {
    			int ca = pl.getCurrentAbility();
    			if(ca < 175) {
    				int pos = pl.getAttribute(PlayerAttribute.POSITIONING);
    				if(pos > MAX_POS) {
    					pl.setAttribute(PlayerAttribute.POSITIONING, MAX_POS);
    					count++;
    				}
    			}
    		}
    
    		System.out.println("Modified count: " + count);
    
    		data.save();
    
    	}
    
    }
    Last edited by JohnLocke; 04-10-13 at 07:08 PM.

  8. #8

    Join Date
    27-03-13
    Posts
    18
    vCash
    500
    Hi,

    I tried downloading the files from the OP, but it looks like the sendspace link is broken. Is there any chance you could upload the files again somewhere? Cheers in advance!

  9. #9

    Join Date
    27-03-13
    Posts
    18
    vCash
    500
    Quote Originally Posted by peadar1987 View Post
    Hi,

    I tried downloading the files from the OP, but it looks like the sendspace link is broken. Is there any chance you could upload the files again somewhere? Cheers in advance!
    Or if anyone who has already downloaded them could send them to me, either would be fantastic.

  10. #10

    Join Date
    27-03-13
    Posts
    18
    vCash
    500
    Nobody? Ah well.

  11. #11

    Join Date
    03-03-12
    Posts
    3,428
    vCash
    1295
    I wouldn't mind this either if somebody has a link that isn't dead

  12. #12

    Join Date
    27-03-13
    Posts
    18
    vCash
    500
    Quote Originally Posted by Coys View Post
    I wouldn't mind this either if somebody has a link that isn't dead
    JohnLocke looks like he's disappeared for a bit. No posts at all in the last month (hopefully he's alright!)

    Looks like the best bet is if somebody downloaded the files and still has them on their computer, but even that's not looking too likely unfortunately

  13. #13

    Join Date
    16-12-11
    Location
    Australia
    Posts
    11,826
    vCash
    0
    Maybe Pasquale tracked him down and has him prisoner working around the clock on the norther Irish offsets

  14. #14

    Join Date
    27-03-13
    Posts
    18
    vCash
    500
    JohnLocke hasn't been online since July. Looks like my strikers will never break 20 goals a season!

  15. #15

    Join Date
    05-06-12
    Posts
    1,035
    vCash
    3700
    link updated in first post.

  16. #16

    Join Date
    27-03-13
    Posts
    18
    vCash
    500
    Quote Originally Posted by JohnLocke View Post
    link updated in first post.
    JohnLocke, you are a prince among men! Hope your absence wasn't due to anything serious, and thanks very much for the link

  17. #17

    Join Date
    27-03-13
    Posts
    18
    vCash
    500
    Probably a total noob question, but when I try and compile the positioningfix, I get this error:

    C:\Users\User\Documents\PositioningFix.java:6: error: cannot find symbol
    import core.files.PlayerAttributes;
    ^
    symbol: class PlayerAttributes
    location: package core.files
    C:\Users\User\Documents\PositioningFix.java:23: error: cannot find symbol
    int pos = pl.getAttribute(PlayerAttributes.POSITIONING);
    ^
    symbol: variable PlayerAttributes
    location: class PositioningFix
    C:\Users\User\Documents\PositioningFix.java:25: error: cannot find symbol
    pl.setAttribute(PlayerAttributes.POSITIONING, MAX_POS);
    ^
    symbol: variable PlayerAttributes
    location: class PositioningFix
    3 errors

    Tool completed with exit code 1

    Has anybody else had this problem? I'd understand if it was struggling to find all of the classes and variables, but the only one it seems to have a problem with is PlayerAttributes.

    Cheers!

  18. #18

    Join Date
    05-06-12
    Posts
    1,035
    vCash
    3700
    My bad, I seem to have renamed something - can you try again? I've amended the above post.

  19. #19

    Join Date
    27-03-13
    Posts
    18
    vCash
    500
    Quote Originally Posted by JohnLocke View Post
    My bad, I seem to have renamed something - can you try again? I've amended the above post.
    Thanks JL, it compiles perfectly now, just have to figure out how to increase my heap size on textpad before it'll let me run it!

  20. #20

    Join Date
    05-06-12
    Posts
    1,035
    vCash
    3700
    Try changing the Parameters box to: -Xmx512m $BaseName

  21. #21

    Join Date
    27-03-13
    Posts
    18
    vCash
    500
    Quote Originally Posted by JohnLocke View Post
    Try changing the Parameters box to: -Xmx512m $BaseName
    Yup, that's working now, and changing positioning values like a mad yoke. They don't all go all the way down to 10, but I'm guessing that's something to do with the game recalculating actual attributes, same as it does when you use a saved game editor.

  22. #22

    Join Date
    05-06-12
    Posts
    1,035
    vCash
    3700
    Full list of attributes:

    GOALKEEPER, SWEEPER, DEFENDER, DEFENSIVE_MIDFIELDER, MIDFIELDER, ATTACKING_MIDFIELDER, ATTACKER, WING_BACK,
    RIGHT_SIDE, LEFT_SIDE, CENTRE, FREE_ROLE,
    ACCELERATION, AGGRESSION, AGILITY, ANTICIPATION, BALANCE, BRAVERY, CONSISTENCY, CORNERS, CROSSING, DECISIONS, DIRTINESS, DRIBBLING, FINISHING, FLAIR, FREE_KICKS, HANDLING, HEADING, IMPORTANT_MATCHES, INJURY_PRONENESS, JUMPING, LEADERSHIP, LEFT_FOOT, LONG_SHOTS, MARKING, MOVEMENT, NATURAL_FITNESS, ONE_ON_ONES, PACE, PASSING, PENALTIES, POSITIONING, REFLEXES, RIGHT_FOOT, STAMINA, STRENGTH, TACKLING, TEAMWORK, TECHNIQUE, THROW_INS, VERSATILITY, VISION, WORKRATE, MORALE.

    Vision is called Creativity in the game, I've kept the wording used by the developers.

  23. #23

    Join Date
    04-03-12
    Posts
    4
    vCash
    500
    I have two questions which could sound silly. Sorry if it so, but I really want to learn more about how you can write code for CM. So the questions:
    1. How could you get player' names based on it's playerID? I didn't find appropriate method for that.
    2. Why some attributes of players have values like -16, -7? Does it mean that the values for this attributes are randomly generated with the start of a new game?
    I would appreciate if you guys give me links to some other useful resources for reading if there are any.
    Thanks.

  24. #24

    Join Date
    02-03-12
    Posts
    4,850
    vCash
    1075
    Quote Originally Posted by byrkof View Post
    1. How could you get player' names based on it's playerID? I didn't find appropriate method for that.
    do you want a list of players ordered by id?

  25. #25

    Join Date
    02-03-12
    Posts
    7,860
    vCash
    45900
    Quote Originally Posted by JohnLocke View Post
    Full list of attributes:

    GOALKEEPER, SWEEPER, DEFENDER, DEFENSIVE_MIDFIELDER, MIDFIELDER, ATTACKING_MIDFIELDER, ATTACKER, WING_BACK,
    RIGHT_SIDE, LEFT_SIDE, CENTRE, FREE_ROLE,
    ACCELERATION, AGGRESSION, AGILITY, ANTICIPATION, BALANCE, BRAVERY, CONSISTENCY, CORNERS, CROSSING, DECISIONS, DIRTINESS, DRIBBLING, FINISHING, FLAIR, FREE_KICKS, HANDLING, HEADING, IMPORTANT_MATCHES, INJURY_PRONENESS, JUMPING, LEADERSHIP, LEFT_FOOT, LONG_SHOTS, MARKING, MOVEMENT, NATURAL_FITNESS, ONE_ON_ONES, PACE, PASSING, PENALTIES, POSITIONING, REFLEXES, RIGHT_FOOT, STAMINA, STRENGTH, TACKLING, TEAMWORK, TECHNIQUE, THROW_INS, VERSATILITY, VISION, WORKRATE, MORALE.

    Vision is called Creativity in the game, I've kept the wording used by the developers.
    movement is off the ball too

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •