Fractal Softworks Forum
May 25, 2017, 07:19:33 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Starsector 0.8.1a In-Development Patch NotesStarsector 0.8a is out (hotfix is up!)
 
   Home   Help Search Login Register  
Pages: [1] 2 3 ... 31
  Print  
Author Topic: [0.7.2a] Console Commands v2.7b (released 2017-03-16; 0.8a WIP available)  (Read 171871 times)
LazyWizard
Global Moderator
Admiral
*****
Posts: 1142


Addicted to complexity


View Profile WWW
« on: August 23, 2012, 01:19:31 AM »

    Console Commands
    An unofficial developer's console
    Download 2.7b for Starsector 0.7.2a (mirror) (requires LazyLib)
    A potentially buggy WIP version for 0.8a can be downloaded here.
    View progress and source code on BitBucket
    Supports Version Checker


    Instructions
    This is installed just like any regular mod. Put it in the mods folder and make sure it's tagged in Starsector's launcher. Once in the game, you can summon the console with control+backspace and enter your commands. While the commands themselves aren't case sensitive, arguments are. For a full list of supported commands enter 'help' in the console. For more information on a specific command use 'help <command>'.

    You can enter multiple commands by separating them with a semicolon. For example, "god;nocooldown;reveal;infiniteflux;infiniteammo" would run all of these combat cheats in a row. RunCode is an exception and can't be used with the command separator.

    If you want to change the key that summons the console or the command separator, you can change these and several other console settings in data/console/console_settings.json.


    Current features:
    • Input commands through a popup window (requires you to run the game in windowed or undecorated mode)
    • A large list of included commands, and the ability to add your own custom commands to the console
    • Write, compile and run code in-game using the Janino library
    • Doesn't require a new game, and can be safely untagged from a running game without issues
    • Should be compatible with all mods, even total conversions


    Included commands:
    Universal commands (6):
    • DevMode, Help, Reload, RunCode, SourceOf, Status

    Campaign commands (40):
    • AddAptitudePoints, AddCredits, AddCrew, AddFuel, AddItem, AddMarines, AddOfficer, AddOrdnancePoints, AddShip, AddSkillPoints, AddSupplies, AddWeapon, AddWing, AddXP, AdjustRelation, AllCommodities, AllHulls, AllWeapons, AllWings, FindItem, FindShip, ForceMarketUpdate, GoTo, Hide, Home, InfiniteFuel, InfiniteSupplies, Jump, Kill, List, OpenMarket, Repair, Respec, Reveal, SetHome, SetRelation, ShowLoc, SpawnFleet, Storage, Suicide

    Combat commands (19):
    • AddCommandPoints, EndCombat, Flameout, God, InfiniteAmmo, InfiniteCR, InfiniteFlux, Kill, NoCooldown, Nuke, RemoveHulks, Repair, Reveal, Rout, ShowBounds, ShowLoc, Suicide, ToggleAI, Traitor

    Some commands are listed under both campaign and combat. These work in both contexts, but function in different ways.


    Troubleshooting
    The input popup never appears when I press the console button in combat:
    • Unfortunately, due to the way the combat pop-up is implemented you must either run the game windowed or in borderless windowed mode to use the console in battle (see instructions below).


    Borderless window instructions
    To enter commands in combat while playing fullscreen you will have to modify your settings.json to enable borderless mode, but you will only have to do this once per Starsector update.

    To run your game borderless, open starsector-core/data/config/settings.json and change "undecoratedWindow" to true and uncomment (remove the # in front of) the "windowLocationX":0 and "windowLocationY":0 lines. Next, untag fullscreen in the game launcher and make sure the game's resolution is set to your native desktop resolution. This should give you a fullscreen borderless window and allow the console popup to function correctly.

    Note that you might have vsync issues if you are on Windows and don't have the Aero theme enabled.


    Screenshots:





    And just for nostalgia's sake, here's the very first WIP image:


    Limitations:
    • The console only functions properly in combat when running windowed or undecorated mode.


    Upcoming/planned features:
    • More commands! If you have any requests let me know in this thread and I'll try to add them to the next version.


    One final note:
    While I've tried to keep everything as user-friendly as possible, this is primarily intended as a tool to aid mod development. This means it does require some knowledge of Starsector's inner workings. Most importantly, you will need to know the internal IDs of various objects in order to use any commands dealing with them. The command "list" will help with this; alternatively these IDs can be found in the data files, usually in the CSVs or variant files.

    Using this mod as a cheating tool will suck all of the fun out of Starsector for you. You have been warned. Smiley[/list]
    « Last Edit: May 05, 2017, 07:11:28 AM by LazyWizard » Logged

    0.8a: LazyLib | Version Checker | Common Radar | Autosave
    0.7.2a: Omnifactory | Console Commands | Simulator Overhaul
    Feel free to use any code I've written or PM me for help with your own.
    LazyWizard
    Global Moderator
    Admiral
    *****
    Posts: 1142


    Addicted to complexity


    View Profile WWW
    « Reply #1 on: September 17, 2012, 09:09:56 PM »

    Here's a tutorial on creating your own commands (this tutorial can also be found in the mod folder):

    This mod supports user-created commands. A major design goal of version 2.0 was to make implementing these commands as painless as possible. This tutorial is intended to explain the new process in detail.

    To add custom commands to the console you'll need a mod that contains two things: your commands' scripts, and the file data/console/commands.csv to register them in. You do not need to add Console.jar to your mod_info.json.

    All commands are contained in their own separate Java class. The console mod loads command classes itself, so you can place the java files anywhere in your mod folder you want - data/console/commands is a good choice as data/console already exists to contain commands.csv. Commands can also be in jars (which shouldn't create a dependency as these classes won't be loaded if the console isn't active).

    It is _highly_ recommended that you do not place your commands in data/scripts. Starsector will automatically compile any scripts in this directory or its subdirectories, and this will cause errors when the console mod is not active. Placing them elsewhere allows you to bundle commands with a regular mod that will only be loaded if the console is tagged in the launcher.

    An example mod that adds several simple commands can be found in the mod folder. If you are the sort who learns best by example, you might find copying from that mod easier than following this tutorial.


     STEP 1 - THE SCRIPT
    =====================

    (Sometimes you may want to start with the CSV row to get a better idea of how your command will look. Just comment out the row by adding a # at the beginning to prevent the game from loading your command until it's finished)

    First off, make sure your IDE has "mods/Console Commands/jars/lw_Console.jar" added as a library. Just follow the same procedure you did to add the Starsector API.

    Your commands must implement the org.lazywizard.console.BaseCommand interface. This interface contains only one method (plus two enumerations, see below):
     - public CommandResult runCommand(String args, CommandContext context)

    'args' is the argument(s) the player entered after this command, for example the command "addcrew 500 elite" would pass in "500 elite" as a single String. Parsing these arguments into something usable is left up to your script. This argument will never be null - if no arguments were entered, an empty String will be passed in instead.

    'context' is a CommandContext passed into your script that tells it where this command was used. CommandContext is the first enum included in BaseCommand, and has the following values (these should be self-explanatory):
     - CAMPAIGN_MAP
     - COMBAT_CAMPAIGN
     - COMBAT_MISSION
     - COMBAT_SIMULATION

    runCommand() returns a CommandResult, which is the other enum included in BaseCommand. CommandResult has the following possible values:
     - SUCCESS, returned when a command runs without error.
     - BAD_SYNTAX, return this if the player entered improperly formatted arguments (for example, a String where an number was expected). The console will automatically display the proper syntax to the player if this is returned.
     - WRONG_CONTEXT, if a command was entered in the wrong place (for example, using a campaign-only command during a mission).
     - ERROR, if a command used the proper syntax but still failed for some reason.

    If you wish to show output to the player, Console.showMessage(String message) will format and print the String passed in to the player.

    With all of this in mind, the basic structure of runCommand() is thus:
     - Check if the context passed in is a valid one for this command. Show a message and return CommandResult.WRONG_CONTEXT if the player used the command in the wrong context (ex: a camapaign travel command during combat).
     - Parse the arguments passed in. If they don't match what is expected, return CommandResult.BAD_SYNTAX (no message is needed; the console mod itself will show the proper syntax from commands.csv if BAD_SYNTAX is returned).
     - Try to run the command with the parsed arguments. If something goes wrong during this stage, show an error message and return CommandResult.ERROR. Console.showException(String message, Exception ex) can be used to display the stack trace of any exceptions to the player.
     - If everything went well, show a message and return CommandResult.SUCCESS

    If you need further help implementing your command, the source files for every core command are included in jars/lw_Console.jar (most modern archive programs can open jars) in the org/lazywizard/console/commands directory. You can also find the most up-to-date source code at bitbucket.org/LazyWizard/console-commands/src


     STEP 2 - THE CSV
    ==================

    After you have written your command's code, you will need to register it so the console can find it. Once you've done this, the mod will automatically load your command when the game starts.

    Commands are registered in data/console/commands.csv. This CSV file has the following columns:
     - command: This is what the user enters to use your command.
     - class: This points to the script you wrote in Step 1 above. Use the fully-qualified name of your class (ex: data.console.commands.Example). This class can be a loose script or inside a jar, the console will work with both.
     - tags: Used with the 'help' command to find specific commands easier. For example, 'help combat' will return a list of all commands with 'combat' as one of their tags. Tags are solely a convenience feature and don't affect how your command functions in any way.
     - syntax: The basic instructions on how to use this command. Shown when a command returns CommandResult.BAD_SYNTAX, or as part of 'help <command>'
       <> - This denotes a required field
       [] - This denotes an optional field
     - help: Detailed instructions on how to use a command. Shown with 'help <command>'

    Command and Class are required. Tags, Syntax and Help can be left empty, but it is HIGHLY recommended that you enter something in these fields unless this command is for personal use only.

    (tutorial last updated 2015-12-11)
    « Last Edit: December 11, 2015, 05:25:16 PM by LazyWizard » Logged

    0.8a: LazyLib | Version Checker | Common Radar | Autosave
    0.7.2a: Omnifactory | Console Commands | Simulator Overhaul
    Feel free to use any code I've written or PM me for help with your own.
    xenoargh
    Admiral
    *****
    Posts: 3491


    View Profile
    « Reply #2 on: September 18, 2012, 01:24:59 AM »

    This is pretty amazing.

    How big of a deal would it be to add some additional data display to the console?  I'd like to use this to display the information my mod needs to function a little more like how I envisioned it; it sounds like adding the relevant commands won't be a big deal, but I'd like to go even further, and use this window to display data to the end-users.  What part of this am I going need to hack to get it done?
    Logged
    xenoargh
    Admiral
    *****
    Posts: 3491


    View Profile
    « Reply #3 on: September 18, 2012, 01:37:37 AM »

    First test run with my mod; crashed when I hit tilde, gives a null error.  I take it that I'll have to install it into the mod?  I haven't changed Corvus as the name of the System.

    It also leaves a copy of itself on the buffer if you move it.

    [EDIT]Installed into my mod; pretty straightforward thus far, it just works, once I got past that hurdle.  This is way, way cooler than it has any right to be, especially considering the size and relative lack of complexity. 

    I'm going to have to go back to square one with how I want to display my mod's data now; I think it makes a lot more sense to build a custom variant of this to serve as the unofficial UI, if I can use it to display changing data...[/EDIT]
    « Last Edit: September 18, 2012, 01:45:31 AM by xenoargh » Logged
    The Soldier
    Admiral
    *****
    Posts: 3553


    Quartermaster


    View Profile
    « Reply #4 on: September 18, 2012, 03:50:48 AM »

    Well...suprize, suprize, LazyWizard has come out with yet another amazing tool. Smiley I'll try it out as soon as I can get to installing it.
    Logged

    Quote from: Trylobot
    I am officially an epoch.
    Upgradecap
    Admiral
    *****
    Posts: 5422


    CEO of the TimCORP


    View Profile Email
    « Reply #5 on: September 18, 2012, 04:25:44 AM »

    Yay @ LazyWizard, for he brings glory to the modding community.





    In all seriousness, this is an awesome tool that will see lots of use by us modders. (?)
    Logged

    LazyWizard
    Global Moderator
    Admiral
    *****
    Posts: 1142


    Addicted to complexity


    View Profile WWW
    « Reply #6 on: September 18, 2012, 08:30:57 AM »

    First test run with my mod; crashed when I hit tilde, gives a null error.  I take it that I'll have to install it into the mod?  I haven't changed Corvus as the name of the System.

    It also leaves a copy of itself on the buffer if you move it.

    Hmm,  I've tested it with several different mods, and it should just work. You should only have to tag it like a regular mod in the launcher.

    It might have been something I changed to get it working without an external jar in this version. I don't suppose you would be willing to re-try and post the complete error stack trace? Cheesy

    How big of a deal would it be to add some additional data display to the console?  I'd like to use this to display the information my mod needs to function a little more like how I envisioned it; it sounds like adding the relevant commands won't be a big deal, but I'd like to go even further, and use this window to display data to the end-users.  What part of this am I going need to hack to get it done?

    As far as I know, not possible at the moment. We don't have access to a GUI API yet, and I don't know enough OpenGL to hack together a library. The 'console' is just a JOptionPane popup right now, with a customized UIManager to fit Starfarer's theme. That's why this mod requires the game to be run in windowed mode to function (and why there would be re-paint issues while it's active - it's completely halting the main thread while the console is visible). Making your own GUI with custom JFrames isn't possible, either. Most Swing components have java.io.File in their hierarchy somewhere, so they will get blocked by Starfarer even after the upcoming changes. I've isolated the input/output in this mod so I can easily replace it if this changes later on.

    However, while it's not a perfect solution, the various showMessage() methods in Console.java do make working with addMessage slightly easier. They support newlines, and word-wrap longer lines for you. Feel free to take any of the code in this mod for your own use. Smiley
    « Last Edit: September 18, 2012, 08:35:47 AM by LazyWizard » Logged

    0.8a: LazyLib | Version Checker | Common Radar | Autosave
    0.7.2a: Omnifactory | Console Commands | Simulator Overhaul
    Feel free to use any code I've written or PM me for help with your own.
    Sproginator
    Admiral
    *****
    Posts: 3582


    Forum Ancient


    View Profile
    « Reply #7 on: September 18, 2012, 09:44:01 AM »

    A fantastic concept, shall try this tonight
    Logged

    A person who's never made a mistake, never tried anything new
    - Albert Einstein

    As long as we don't quit, we haven't failed
    - Jamie Fristrom (Programmer for Spiderman2 & Lead Developer for Energy Hook)
    xenoargh
    Admiral
    *****
    Posts: 3491


    View Profile
    « Reply #8 on: September 18, 2012, 10:26:40 AM »

    If we have access to OpenGL at all, then all we really need access to is:

    1.  Whatever Alex is using to display the text glyphs.  I presume that's a simple command
    2.  Graphics within the starfarer directory defined within a .JSON somewhere.

    We can do the rest fairly easily, if we're already allowed to capture mouse-click events and keystrokes.
    Logged
    LazyWizard
    Global Moderator
    Admiral
    *****
    Posts: 1142


    Addicted to complexity


    View Profile WWW
    « Reply #9 on: September 18, 2012, 10:31:42 AM »

    I don't know what all we have access to, actually. Out of the entire LWJGL library, I'm only using Vector2f, Display.isFullScreen(), and Keyboard.isKeyDown().
    Logged

    0.8a: LazyLib | Version Checker | Common Radar | Autosave
    0.7.2a: Omnifactory | Console Commands | Simulator Overhaul
    Feel free to use any code I've written or PM me for help with your own.
    xenoargh
    Admiral
    *****
    Posts: 3491


    View Profile
    « Reply #10 on: September 18, 2012, 10:38:37 AM »

    Try this out.

    [EDIT]I'll try to hack a simpler version later; we really don't need GLSL to just draw a quad, lol.  But if we can draw textured quads, using named textures already available through Starfarer, and can call the text glyph system to present text at X,Y, then we can build just about anything we'd want to do... right there, in the game, like anything else in the UI.[/EDIT]
    « Last Edit: September 18, 2012, 10:47:48 AM by xenoargh » Logged
    LazyWizard
    Global Moderator
    Admiral
    *****
    Posts: 1142


    Addicted to complexity


    View Profile WWW
    « Reply #11 on: September 18, 2012, 11:00:36 AM »

    Quick update: I made the source repository public - you can find it in the main post. The default branch won't work with Starfarer, so you will want to grab the noreflect branch.

    It's a Mercurial repository because that's what I use for my solo projects. Sorry, Git/SVN users.


    Try this out.

    [EDIT]I'll try to hack a simpler version later; we really don't need GLSL to just draw a quad, lol.  But if we can draw textured quads, using named textures already available through Starfarer, and can call the text glyph system to present text at X,Y, then we can build just about anything we'd want to do... right there, in the game, like anything else in the UI.[/EDIT]

    If we can, that would be awesome. Cheesy
    Logged

    0.8a: LazyLib | Version Checker | Common Radar | Autosave
    0.7.2a: Omnifactory | Console Commands | Simulator Overhaul
    Feel free to use any code I've written or PM me for help with your own.
    Alex
    Administrator
    Admiral
    *****
    Posts: 10594


    View Profile
    « Reply #12 on: September 18, 2012, 11:03:35 AM »

    Hah, very interesting. Haven't had a chance to try it, but kudos for putting this together Smiley

    it's completely halting the main thread while the console is visible.

    Really? Unless you're on a Mac, it shouldn't do that. But since I don't know where you're calling JOptionPane from... ahh, I guess that would explain it. If the code displaying it ends up on the main loop somewhere (and it probably does), then I it'd hang there until it was done. So, never mind.

    Try this out.

    [EDIT]I'll try to hack a simpler version later; we really don't need GLSL to just draw a quad, lol.  But if we can draw textured quads, using named textures already available through Starfarer, and can call the text glyph system to present text at X,Y, then we can build just about anything we'd want to do... right there, in the game, like anything else in the UI.[/EDIT]

    Don't bother with shaders. Starfarer uses the fixed function pipeline, and the two are incompatible. Shaders are an all-or-nothing way of doing it - you can't only use them for some things.

    If you're not familiar with OpenGL, I'd suggest being very careful. It's pretty easy to crash the graphics driver by doing some ill-advised OpenGL calls - which can mean a system hang / hard reboot.

    Although, that's kind of a moot point. Since there are currently no callback from within the rendering portion of the loop, anything you try to draw would get cleared out before the start of the next frame's rendering - you'd never see it.

    We can do the rest fairly easily, if we're already allowed to capture mouse-click events and keystrokes.

    There's some potential for unintended interactions here, too (using Keyboard.poll() or Mouse.poll() would break the game).
    Logged
    LazyWizard
    Global Moderator
    Admiral
    *****
    Posts: 1142


    Addicted to complexity


    View Profile WWW
    « Reply #13 on: September 18, 2012, 11:13:21 AM »

    Hah, very interesting. Haven't had a chance to try it, but kudos for putting this together Smiley
    I don't suppose you would be willing to try the main branch and see if it runs in the latest development version? Cheesy I've been using a lot of guesswork, but I'm almost certain it will work without tweaking given the changes you mentioned in our conversation.

    it's completely halting the main thread while the console is visible.

    Really? Unless you're on a Mac, it shouldn't do that. But since I don't know where you're calling JOptionPane from... ahh, I guess that would explain it. If the code displaying it ends up on the main loop somewhere (and it probably does), then I it'd hang there until it was done. So, never mind.

    I intentionally called it that way, as it makes things much simpler for me. I did try making a multi-threaded version of this mod instead of using a SpawnPointPlugin, but there were so many edge cases (foremost being making sure the player is actually on the campaign map when the command is finally entered) that it just wasn't worth fixing all the potential pitfalls. The console implementation is isolated so I can replace it later if I change my mind. Smiley
    Logged

    0.8a: LazyLib | Version Checker | Common Radar | Autosave
    0.7.2a: Omnifactory | Console Commands | Simulator Overhaul
    Feel free to use any code I've written or PM me for help with your own.
    xenoargh
    Admiral
    *****
    Posts: 3491


    View Profile
    « Reply #14 on: September 18, 2012, 11:15:57 AM »

    If it's just using fixed-function pipeline, that's fine; all we really need to do is draw some textured quads and make calls to display strings via your glyph system, nothing terribly fancy.

    Anyhow,

    Code:
    import org.lwjgl.opengl.GL11;
    import org.lwjgl.util.glu.GLU;
    That's already compiling, so we're fairly close.  It's too bad we don't have a callback atm, I think that simple test stuff's already possible.

    Quote
    There's some potential for unintended interactions here, too (using Keyboard.poll() or Mouse.poll() would break the game).
    Yeah, we'd need to know how to safely do that.

    Pretty stoked, though; instead of pestering you about building some UI stuff, we could just do it, I think.
    Logged
    Pages: [1] 2 3 ... 31
      Print  
     
    Jump to:  

    Powered by MySQL Powered by PHP Powered by SMF 1.1.20 | SMF © 2006-2011, Simple Machines
    Simple Audio Video Embedder
    Valid XHTML 1.0! Valid CSS!