Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

Boom Box

Discussion in 'Programming Released Codes' started by Bullet_Force, Aug 4, 2018.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. Bullet_Force Apprentice Engineer

    Messages:
    366


    Workshop Link: https://steamcommunity.com/sharedfiles/filedetails/?id=1449322832

    The Boom Box is a Space Engineers virus designed to cause destruction on any grid it happens to exist on. It comes with 66 prepacked unique behaviors that range from the very subtle to the highly destructive. It also has 4 modes of operation that allow the user to configure it to activate however they wish.

    Uses:
    Sabotage - Join your enemies faction and 'enhance' their ships and grids with destructive results.
    PVP on PVE - Legally create some carnage on PVE servers that otherwise ban PVP.
    Rig Duels - Never lose a duel again against a friend by enhancing their fighter with this.
    Emergency Tests - Test how well someone can react to an emergency situation

    Major Default Settings:
    Mode 2:
    Behavior Type: 2
    Delayed Start: 1 minute
    Debug Mode: False
    Cascade Mode: False
    Camouflage: 3
    Command Mode: False
    Command Override: True
    Disable Jumping: True


    Self Preservation:
    The virus has a variety of mechanisms to ensure its own survival:

    Camouflage:
    The virus upon running has the option to disguise itself as another block with and then hide itself in the terminal. It will choose from the following blocks:
    • Small Reactor
    • Small Cargo Container
    • Camera
    • Gyroscope (If not a station only)

    In addition it will falsify block data to mimmick those of the block it is pretending to be. For instance if it hides itself as a "Small Reactor" when clicked on the block will show the following in the detailed info panel:
    Camouflage Settings
    The higher settings will inherit the lower ones except for 0. Ie setting Camouflage to 4 will do everything except 0.​
      • 0 - Off
      • 1 - Fake name
      • 2 - Fake name and fake description
      • 3 - Hide in Terminal and Toolbar
      • 4 - Chameleon Mode. The virus will constantly change its appearance. New name and new description every 1 second.
    Anti Tamper:
      • The virus will enrage if someones tries to grind its block, instantly detecting it and enabling behavior type 5.
    Disable Jumping
    If enabled the virus will constantly turn off and then on the jump drives on the grid effectively making it impossible to jump resulting in an aborted jump each time. This will cost the user power and recharge time everytime they try.

    Modes

    The virus has 4 modes which dictate how the virus will activate.

    1. Cockpit Activation - Will only activate the virus and run when someone is sitting in a cockpit.
    2. One Time Cockpit Activation - Will only activate the virus when someone is sitting in a cockpit, but once activated it will continue to run.
    3. Constant Activation - Will always activate and run the virus.
    4. Awaken - This will set virus to be dormant, awaiting the right code word via antenna to awaken and spring into life.

    In addition to these 4 modes there is the Timed Activation Mode which can turned on by setting the variable "delayedStart" to true. If this is true it will override the 4 modes, which will then have to wait for the correct amount of time to elapse before they can become active.

    Behavior Types
    The virus has 5 behavior type categories which a user if they wish can choose to use. These categories contain numerous behaviors in them which align to the conditions below.

    0. All Options - The virus will run any of its assigned behaviors ranging from turning off the lights to the entire ship exploding.
    (Behaviors 1 - 66)
    1. Stealth - Small innocuous changes that will make the pilot feel like they are going slightly mad. (Behaviors 1 - 12)
    2. Subtle - The ship will seem to have a mind of its own. Some rather odd behavior will occur (Behaviors 13 - 21)
    3. Less Subtle -The ship will seem to have a mind of its own. Some systems will randomly fail. No physical damage expected. (Behaviors 22 - 33)
    4. Deadly - The ship will begin to spiral out of control. Major systems will fail, weapons will activate. Complete loss of control will be achieved. High Damage Expected (Behaviors 34 - 48)
    5. Evil - The ship will take on a mind of its own. Extreme damage expected. (Behaviors 49 - 66.
    Command Line Inputs:
    • template - generates a blank template
    • cleanup - runs cleanup which will restore the grid to its original state
    • stop - stops the virus from running
    • scan - scans the grid for updates to it such as blocks being added or removed

    Templates:
    With templates settings can be swapped in and out very easily.
    To use the template system:
    1. First run the command: <<TEMPLATE>>
    2. This will generate a default template with all available settings in the Boom Box's Custom Data.
    3. Open the Custom Data field and edit the template values
    4. Any template fields omitted will resort to using the default values specified in the script settings.

    For example if you wanted to set "mode" to 4 it would look like this:
    <<TEMPLATE>>
    <<MODE>>4<</MODE>>
    <</TEMPLATE>>

    Default Template: (I have put examples of acceptable data next to each field):
    Code:
    <<TEMPLATE>>
    <<CODE>><</CODE>> ie EXPLODE
    <<MODE>><</MODE>> 1-4
    <<BEHAVIOUR TYPE>><</BEHAVIOUR TYPE>> 1-5
    <<DEBUG>><</DEBUG>> true/false
    <<REFRESH TIME>><</REFRESH TIME>> ie 20
    <<CLEAN UP>><</CLEAN UP>> true/false
    <<RUN ONCE>><</RUN ONCE>>true/false
    <<CASCADE>><</CASCADE>> true/false
    <<ASCEND>><</ASCEND>> true/false
    <<COMMAND>><</COMMAND>> true/false
    <<COMMAND OVERRIDE>><</COMMAND OVERRIDE>> true/false
    <<TEST MODE>><</TEST MODE>> true/false
    <<LOG>><</LOG>> true/false
    <<COCKPIT NAME>><</COCKPIT NAME>> ie MyCockpit
    <<RUN IN ORDER>><</RUN IN ORDER>> true/false
    <<CAMOFLAGE>><</CAMOFLAGE>> 0-4
    <<DELAYED START>><</DELAYED START>> true/false
    <<DAYS>><</DAYS>> ie 1
    <<HOURS>><</HOURS>> ie 5
    <<MINUTES>><</MINUTES>> ie 6
    <<SECONDS>><</SECONDS>> ie 9
    <<ELEVATION MIN>><</ELEVATION MIN>> ie 200
    <<ELEVATION MAX>><</ELEVATION MAX>> ie 800
    <<GRAVITY MIN>><</GRAVITY MIN>> ie 0.2
    <<GRAVITY MAX>><</GRAVITY MAX>> ie 1.0
    <<SPEED MIN>><</SPEED MIN>> ie 20.5
    <<SPEED MAX>><</SPEED MAX>> ie 100.5
    <<LIDAR RANGE>><</LIDAR RANGE>> ie 245.5
    <<BEHAVIOURS>><</BEHAVIOURS>> ie 1,2,3,4
    <<PHRASES>><</PHRASES>> ie "hi", "hello"
    <<PBS>><</PBS>> MyProgramBlock<->shoot weapons<+>MyProgramBlock2<->turn off
    <<TIMERS>><</TIMERS>> MyTimerBlock<->20<+>MyTimerBlock 2<->30
    <</TEMPLATE>>
    Clean Up
    The virus has the option to restore the grid to its original state at compile time. If enabled it will attempt to revert any damage it has caused. All blocks will be renamed to their correct names and have their original settings restored.

    Other Settings:
    New In Version 46:
    Templates - See The Templates Section
    pbList - A list of program blocks and their run commands
    How to use(put between { } seperated with ","
    EXAMPLE new KV("PB Weapons","shoot all")

    timerList - A list of timer blocks and the countdown delay in seconds.
    How to use(put between { } seperated with ","
    EXAMPLE: new KV("Warhead Timer","10")

    New In Version 45:
    Command Override: This tells the script to allow external antenna signals to override its current settings while it is already running. This will not work if Command Mode is enabled.

    New In Version 40:
    Test Mode - The program will run and simulate the virus and its behaviors without actually doing anything. This is useful to see what behaviors will run on a particular grid.
    Command Mode - With this enabled the virus will not run any behaviors on its own grid, instead it will always run behavior 59 and will attempt to pass its current behaviors to other grids except for command mode which it will not pass.
    Logging - The virus will log itself to the program block's custom data field, outputting all actions it performs with a timestamp.

    Refresh Time - How often in seconds the virus should run. Smaller numbers may affect server performance. (Default 10 seconds).
    Behaviors List - The user can set a range of specified behaviours by listing them in the "behavioursList" variable. The virus will then only run those behaviors.
    Phrases List - The user can set a list of words and sentences to be used when the script edits LCD's and Beacons.
    Cascade - The virus will run behavior after behavior without clearing the previous ones.
    Ascend - The virus will run all the behaviors from 1 to 59 in order, progressively getting worse.
    Clean Up - The virus will cleanup after itself after running a behavior, deactivating some of its damage.
    Cockpit Name - If you only want the virus to activate when a specific cockpit is occupied specify the name here.
    Run Once - The virus will run only once.
    Target Elevation Minimum - The minimum height from a planet/moon for behaviors that use this to activate.
    Target Elevation Maximum - The maximum height from a planet/moon for behaviors that use this to activate.
    Target Gravity Minimum - The minimum amount of gravity for behaviors that use this to activate.
    Target Gravity Maximum -The maximum amount of gravity for behaviors that use this to activate.
    Target Speed Minimum - The minimum speed for behaviors that use this to activate.
    Target Speed Maximum - The maximum speed for behaviors that use this to activate. (Will need to be higher if server uses speed mods.)
    Lidar Target Range - The minimum distance in metres that Lidar/Raycast based behaviors will activate.


    Behaviors and Codes: **
    1. Hide random blocks from the terminal and toolbar
    2. Cameras and Sensors Disabled. The cameras and sensors turn off.
    3. Brownout. Half of the reactor power on the ship is turned off
    4. Randomize & Toggle Sensors - The sensor values are randomized and toggled on/off
    5. Drain Batteries. The reactors and solar panels switch off and the grid switches to using battery power
    6. Disable Decoys. All decoys on the grid are turned off
    7. Toggle Ore Detectors
    8. Disable Medical Bays & Oxygen Generators
    9. Refineries and Arc Furnaces Disabled
    10. Assemblers Disabled
    11. Disable Conveyors & Production
    12. Disable Weapons - All weapons the grid have their target systems disable but are still set to rotate and move to maintain the illusion that they are on
    13. Toggle Lights - The lights are turned on or off
    14. Erase LCD's
    15. Random Sound - A random sound is chosen and played with random volume levels, loop and ran
    16. Toggle Antennas - The antennas are turned on or off
    17. Toggle Beacons - The beacons are turned on or off
    18. Toggle Projectors - The projectors are turned on or off
    19. Add Small Random Text OR Phrase To LCD's. A small word or user defined phrase is added to LCD's.
    20. Fiddle With Doors. The doors on the grid randomly open or close.
    21. Enable Gravity Generators. The gravity generators are switch on with maximum power in a random direction
    22. Toggle Landing Gear - The landing gear are turned on or off
    23. Toggle Connectors - The connectors are turned on or off
    24. Toggle Grinders - The grinders are turned on or off
    25. Toggle Drills - The drills are turned on or off
    26. Toggle Program Blocks & Timers - Program Blocks and Timers blocks are turned on or off
    27. Activate Timer
    28. Run Program Block
    29. Throw Out Cargo - Connectors will begin dumping cargo using the conveyor system to pull it and then dump it.
    30. Toggle Air Vents. The air vents are toggled which could result in explosive decompression or a waste of a oxygen.
    31. Random Lighting - The lights on the grid randomly flicker, change colors, turn off/turn on and change their intensity.
    32. Enable Welders & Projectors. All welders are turned on and all projectors are turned on
    33. Random Large Texr/Phrase In LCDs. All LCD's are hijacked with spam of your choosing.
    34. Antennas On + Random HUD Blocks Enabled. Rrandom blocks are set to display on Hud as well as Antenna On.
    35. Random Large Text/Phrase on Antennas Beacons. All Antennas/Beacons are turned on and given a different name either generated randomly or based on a user supplied phrase.
    36. Weak Gyro Power. The power level of the gyros on the grid are reduced by a random amount
    37. Weak Random Gyros. The gyros on the ship come alive and slowly move the ship around
    38. Slight Thrust. A single thruster self activates with a random low amount of power.
    39. Activate Parachutes. All the parachutes on the grid activate, costing materials
    40. Disable cockpit control. The cockpits on the ship lose the ability to control thrust and dampners/handbrakes are set to off
    41. Disable Gyros. The gyros are turned off.
    42. Disable Thrusters. The thrusters are turned off
    43. Disable Power. All Power is turned off on the grid (The Virus will reactivate automatically once power is restored)
    44. Disconnect Rotors. The rotors on the grid are set to a high velocity and then the ends are disconnected.
    45. Extend and Disconnect Pistons. All pistons are the grid are fully extends and then have their ends disconnected
    46. Disconnect Merge Blocks. All merge blocks on the grid are disconnected.
    47. Activate and Run All Program Blocks and Timers
    48. Randomize Jump Drives. The jump drives on the grid have their blind jump ranges randomized from 0% to 100% and the recharge setting is switched to off.
    49. Random Block Names. All the blocks on the grid are randomly renamed with a random string
    50. Re Order Block Names. The block names on the grid are shuffled around ie "Small Reactor 3" becomes "Ion Thruster 1".
    51. Extreme Rotation. The gyros on the ship come alive and begin spinning the ship out of control
    52. Strong Random Gyros. The gyros come alive and violently move the ship around in random directions
    53. Extreme Thrust. All the thrusters in one random direction are set to maximum power, dampeners are disabled.
    54. Fire Gatling Guns. All gatling guns on the ship suddenly start shooting.
    55. Fire Rockets. All rockets on the ship suddenly start shooting
    56. Fire Gatling and Interior Turrets. All gatling and interior turrets start shooting
    57. Fire Missile Turrets. All missile turrets start shooting.
    58. Fire All Weapons. All weapons on the grid fire.
    59. Throw & Shoot - Throw out cargo and tell turrets to target it
    60. Enable Gravity Generators + Mass Blocks/Space Balls. If a ship is using a Gravity Drive for propulsion it will come back to bite.
    61. Disable Landing Gear, Connectors, Merge Blocks and Accelerate. All disconnctable blocks are disconnected and the ship accelerates with full thrust in a random direction
    62. Enable Autopilot. The ship comes alive. Random GPS locations are added and the autopilot is told to fly there with collision avoidance turned off.
    63. Deactivate Parachutes and Descend. If the ship is in an atmosphere, within a user defined height, speed and gravity field, it will turn off all parachutes then engage full down thrust.
    64. Explode Warheads. All warheads on the grid are armed and told to explode.
    65. Lidar Scan and Accelerate. The Virus takes over all cameras on the grid and turns them into scanners. If they detect any grid or asteroid within a user defined distance, the ship will engage full thrust and head in that direction.
    66. Chain Reaction. The virus begins activating dormant viruses within antenna range by passing them the correct code word. The virus can pass to them behaviors and settings to execute.

    * The virus will work on all friendly and neutral blocks.
    **Note some of these behaviours won't execute if the conditions are not correct. Example: Trying to run the "Fiddle With Doors" behaviour on a small ship. Other ones include behaviours that aren't suitable for fixed stations such as thruster and gyro movements and autopilot.
    When this occurs the Virus will run itself again and find a new behaviour.
     
    Last edited: Dec 11, 2018
  2. Bullet_Force Apprentice Engineer

    Messages:
    366
    I am looking for some advice on what I can improve in my code to make it more efficient and also shorter.. Its currently very large at 98598 chars out of 100,000.

    This is the code from the current version:
     
    Last edited: Aug 25, 2018
  3. Malware Master Engineer

    Messages:
    9,861
    The first thing I could advise you to do, before I've even looked at your code, is to take a look at this:
    https://github.com/malware-dev/MDK-SE/wiki/Getting-Started

    MDK is a plugin for Visual Studio which aids in creating and maintaining script projects, as well as deploying to Space Engineers. It also features an optional minifier. This alone will shrink your script down significantly, at the cost of readability.
    --- Automerge ---
    The second thing I should advice you is to not create new lists every time your script runs. Constant memory allocation is highly inefficient and affects game performance, especially in a multiplayer game where multiple such scripts might run. Create your lists as class fields, and reuse them. The grid terminal system clears them for you on retrieval.

    It is also highly recommended to fetch and cache, not fetch every time, as the process of fetching is also relatively slow. If you need to keep your lists updated, consider updating them only once in a while and perhaps in a staggered fashion.

    As for your switch, I don't know. But you'll get far with a minifier.
     
    Last edited: Aug 21, 2018
  4. Bullet_Force Apprentice Engineer

    Messages:
    366
    Wouldn't making them as class fields be the same thing, because it would be fetching all the lists everytime I made a new object which would be once per run.

    I didn't understand this part, the GTS reallocates the memory for the list after retrieval?

    So parsing the storage is faster then retrieving blocks via the GTS? In that case if I saved all the lists to storage then retrieved them each run, that would be better?

    I was trying to think of a way to convert the behaviors to a class but since they are all so varied, it doesn't seem to be possible.

    I have been using Visual Studio but I'll check out this MDK thing. The minifier sounds handy :)
     
  5. Malware Master Engineer

    Messages:
    9,861
    No. Lists are quite clever things. They allocate a buffer that grows as needed, but when you clear a list, they don't clear their buffer. This means that a grid terminal retrieval will simply be reusing the same memory you used last time, which is much more efficient. However, if you recreate the lists every time, they need to go through the whole allocation process again. Which is why it's best to reuse lists.

    No. A script isn't recreated every time it's run. It's instantiated once and reused. Which means that class fields will be retained between calls to Main; you don't need to use Storage at all. Storage is only when you need to persist between sessions, i.e. game reloads or server restarts. So if you use class field lists as mentioned above, you only need to update them every now and again to make sure you retrieve any changes.
     
  6. Bullet_Force Apprentice Engineer

    Messages:
    366
    Ok that makes more sense.


    That is really interesting I didn't know that about that with the classes. That will make a big difference.
    --- Automerge ---
    @Malware Hi I was testing your suggestion to keep the lists in a class because the class remains in memory but I found an issue during testing. I noticed when I deleted a block off the grid, it was still in the list even though it was no longer on the grid.

    I tried setting the non existent block to having a new name and it didn't seem to fail which seems odd given its not referencing anything anymore. I'm guessing its a copy of the original block in memory?

    What would be a good way to handle this/refresh the list?

    Update: I've decided to update and fill the lists as they are required if that particular behavior is chosen. This way if the ship gets damaged and parts come loose it won't affect the script.
     
    Last edited: Aug 22, 2018
Thread Status:
This last post in this thread was made more than 31 days old.