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.

Modding API - new requests

Discussion in 'Modding API' started by joeblack616, Oct 22, 2014.

Thread Status:
Not open for further replies.
This last post in this thread was made more than 31 days old.
  1. Timfa Trainee Engineer

    Messages:
    9
    I'd actually like to open up more options between the ModAPI and the Ingame ModAPI.

    I recently tried to add more functionality to programming blocks. I started out with sending chat messages over antennas, with the goal being to find out how to expose methods to the programmable block.
    I tried making a static class in the Sandbox.ModAPI.Ingame namespace, but I have a feeling I'm still bumping into the whitelist. (ModAPI.Ingame may be accessible, but my class inside is not?)

    So! My request is having some way for modders to whitelist their own namespaces or methods in the programming block.
    Since this opens up a possibility to go around said security feature, there obviously needs to be some sort of warning when using the mod.

    My idea is this:

    Some namespaces are hard-blacklisted;
    First the blacklist is applied (Everything in System for example), then the existing whitelist (which overrides the blacklist), and then the modmaker's-whitelist (which cannot override the previous two lists)

    When a user then enables a mod which whitelists it's own methods, the user gets a warning containing:
    • "This mod is exposing stuff to the Ingame Programming Block. This can be dangerous, only use this if you have complete trust in the mod developer"
    • A list of namespaces/classes which the whitelist adds
    • If an existing documentation exists online (when exposing System or Microsoft namespaces for example, an online documentation page usually exists) clicking in the list opens that page, so that the user gets some insight into what exactly the players can do with this functionality (Is this good, or can this cause problems?)
    • If there is none (it's a custom namespace/class the modder made for example) clicking a list item will show the code inside. Most normal users may not be able to read it, but it might deter people that don't know what they're doing from messing up their server (or even their entire pc!), while giving users with programming experience a look into what the code does, so you can inspect if you actually want this in-game.
    Of course, a similar message is shown when you join a server with such a mod enabled (with a "pls don't show this again" button maybe)
    Another idea is only allowing namespaces and classes from within Sandbox.ModAPI.Ingame.Custom. This assures only custom methods are used (though some system would need to be designed to blacklist harmful things such as System.IO wiping your HDD and such)

    While I'm well aware that this can potentially be risky, I feel that when those risks are clearly shown upon enabling a mod and the user gets enough info about what is added, this can make for some pretty amazing options for in-game programmers. (allowing scripted changes of block color for ANIMATED RAINBOW SHIPS! or active-camo stuff for boring people) This would also potentially free up more developer time. Since modusers can add their own in-game methods, they would no longer have to ask for some methods to be whitelisted. And it would of course simplify code in programming blocks as well; Users could, through mods, add functions which return a list of damaged blocks for example, giving people newer to programming the option to fiddle with this without downloading a massive script they'll never understand or be able to modify to actually do what they want.
     
  2. soknorb Trainee Engineer

    Messages:
    65
    We could really use a way to get what ores are inside an asteroid and where in the asteroid they are.
    If this is implemented then we can do things like program mining drones, asteroid scanners, set up custom asteroid/ore distribution - for more challenge.
    If this is made better then I will get to work right away on some of these ideas.
     
  3. midspace Senior Engineer

    Messages:
    2,224
    This information is already available, as I use it in the Admin helper mod, with the "/scanore" chat command.
    http://steamcommunity.com/sharedfiles/filedetails/?id=316190120
     
  4. soknorb Trainee Engineer

    Messages:
    65
    I almost had what I needed but could not figure out how to properly get ReadRange to work. Thank you Midspace!
     
  5. Sp[a]cemarine Apprentice Engineer

    Messages:
    101
    @joeblack616
    I'd like to have access (getter is enough, of course) to the field 'Sandbox.Game.Weapons.MyEngineerToolBase.Owner'. For me it is not really important how exactly I can access it. The reason for the request is that even though I get the entityId of the attacker with the damage system, in case of grinding it will only return the entityId of the grinder. Therefore it's not possible to determine the grinder's owner. This might be only a small request but with this small change a proper anti grief mod could be realized and I think that's a feature many engineers dream about. So let's make that happen!
     
    • Agree Agree x 1
  6. midspace Senior Engineer

    Messages:
    2,224
    We'd like a SaveEvent, that tells us when the game (Client and/or Server) saves, so our API Mods can save their content at the same time, that way it stays in sync with the game.
     
    • Like Like x 1
  7. Digi Senior Engineer

    Messages:
    2,393
    What's wrong with MySessionComponentBase's SaveData() ? I've used it in my Chat History mod to save the messages when the server saves and it works fine, I don't know if it triggers for clients but it should.
     
  8. midspace Senior Engineer

    Messages:
    2,224
    I hadn't seen that one. It doesn't have code documentation, and isn't named like "OnSave..." to indicate its purpose.
    I'll give it a try :D thanks!
    Edit: It works!
     
    Last edited: Sep 19, 2015
  9. leftler Trainee Engineer

    Messages:
    76
    VRage.Library.Utils.MyGameTimer provides a wrapper around Stopwatch you can use for high accuracy time measurements.
     
  10. midspace Senior Engineer

    Messages:
    2,224
    A couple of methods from MyPhysics need to be made accessible to the ModAPI (either whitelist them directly, or wrapper or interface them from other whitelisted types).

    Sandbox.Engine.Physics.MyPhysics.CastRay(Vector3D from, Vector3D to, List<MyPhysics.HitInfo> toList, int raycastFilterLayer = 0)

    and

    Sandbox.Engine.Physics.MyPhysics.Clusters.EnsureClusterSpace(...).
     
  11. Draygo Senior Engineer

    Messages:
    1,297
    Whitelist request for System.BitConverter which has a ton of useful stuff dealing with byte[] arrays.
     
  12. ONull Trainee Engineer

    Messages:
    54
  13. rexxar Senior Engineer

    Messages:
    1,532
    I think someone else mentioned whitelisting System.BitConverter, and I'd like to add my vote for that as well.
     
    • Agree Agree x 1
  14. rexxar Senior Engineer

    Messages:
    1,532
    Please whitelist IMyInput. I've got some ideas for an in-game UI, but I sort of need to capture keypresses
     
    • Agree Agree x 1
  15. xphoenixxx Junior Engineer

    Messages:
    529
    How about sound? Correct me if I am wrong (and i frequently am) I was surprised to discover today that nobody knows of a way to trigger a sound in the game client that doesn't involve a modded block or custom sound via a sound block.

    It appears there is plenty of sound related stuff under Vrage.Audio but anyone I ask says it isn't whitelisted.

    As far as i can tell the only way i could play a simple audio prompt using either a built in or custom sound (in my mods /audio/ folder for example) is:
    a: spawn a soundblock with power, trigger the sound, remove sound block
    b: create a custom invisible block that uses my custom sound as its ambient sound then remove it
    c: force players to build a sound block (which wont work outside of a ship)

    None of these would allow a simply client side only sound to play which is what most modders would need.
    I want to play a sound when a player reaches a given area. It would also be useful later when using MyAPIGateway.Utilities.GetObjectiveLine().AdvanceObjective(); to play an appropriate objective complete sound

    Thought? Flames? Suggestions? Death Threats?
     
  16. Gwindalmir Senior Engineer

    Messages:
    1,006
    Use MyEntity3DSoundEmitter, it's whitelisted.

    Then you can use something like this to play a sound:
    Code:
    		private MyEntity3DSoundEmitter m_soundEmitter;
    		public MyEntity3DSoundEmitter SoundEmitter { get { return m_soundEmitter; } }
    		m_soundEmitter = new MyEntity3DSoundEmitter(Container.Entity as VRage.Game.Entity.MyEntity);
     
    		public static void PlaySound(this IMyFunctionalBlock ftl, string soundname, bool stopPrevious = false)
    		{
    			MyEntity3DSoundEmitter emitter = null;
     
    			if( ftl.IsFTL() )
    				emitter = ftl.GameLogic.GetAs<FTL>().SoundEmitter;
    			if( emitter != null )
    			{
    				if (string.IsNullOrEmpty(soundname))
    				{
    					emitter.StopSound((emitter.Loop ? true : false), true);
    				}
    				else
    				{
    					MySoundPair sound = new MySoundPair(soundname);
    					emitter.CustomMaxDistance = (float)ftl.GetTopMostParent().PositionComp.WorldVolume.Radius * 2.0f;
    					Logger.Instance.LogDebug("Distance: " + emitter.CustomMaxDistance);
    					emitter.CustomVolume = 1.0f;
    					emitter.PlaySound(sound, stopPrevious);
    				}
    			}
    		}
    The 'soundname' is the subtype in Audio.sbc.
    Don't mind the mess, I ripped it from my mod.
     
    • Informative Informative x 1
  17. xphoenixxx Junior Engineer

    Messages:
    529
    Ah nice thanks; hopefully this should allow some interesting things!

     
  18. Ravenal Apprentice Engineer

    Messages:
    362
    I have mentioned this before in the past can we get these added?
     
  19. Tristavius Senior Engineer

    Messages:
    1,368
    @joeblack616 Request for a couple of improvements to thruster upgrade module modding.

    Firstly, at the moment we only have the ability to utilize m_thrustMultiplier and m_powerConsumptionMultiplier - it would be very useful to allow the upgrade module to add a value to the BlockDefinition.ForceMagnitude rather than multiplying it (example: 4kn thruster with an upgrade module that adds 6kn will become 10kn).

    Secondly, opening up some of the flame properties would also be useful, specifically FlameDamageLengthScale, FlameDamage, FlameLengthScale and possibly the colours would also be very useful - it would allow an upgraded thruster to have an appropriately upscaled flame effect.

    Cheers!
     
  20. XCython Trainee Engineer

    Messages:
    3
    I have a whitelist request for IMyUseObject. I need to interact with a physics-disabled grid and open its inventory with a keypress, and it would easily allow for both.
     
  21. Rynchodon Trainee Engineer

    Messages:
    35
    In the development version, these are no longer accessible. Please restore them.
    Code:
    System.ObsoleteAttribute
    System.ThreadStatic
    System.TypeCode
    System.Runtime.CompilerServices.CallerLineNumberAttribute
    System.Runtime.CompilerServices.CallerMemberName
    System.Runtime.InteropServices.FieldOffsetAttribute
    System.Runtime.InteropServices.LayoutKind
    System.Runtime.InteropServices.StructLayoutAttribute
    VRage.Exceptions
    VRage.FastResourceLock
    
     
  22. KageJ Guest

    Requests:

    ModAPI.IMyCubeBlock.SlimBlock to access https://github.com/KeenSoftwareHous...x.Game/Game/Entities/Cube/MyCubeBlock.cs#L175

    Having the reverse lookup would be helpful, would also make sense to add it to Ingame.


    ModAPI.IMySlimBlock.Min to access https://github.com/KeenSoftwareHous...ox.Game/Game/Entities/Cube/MySlimBlock.cs#L84

    We have IMySlimBlock.Max, but not Min.



    ModAPI.IMyLargeTurretBase.Target to access https://github.com/KeenSoftwareHous.../Game/Weapons/Guns/MyLargeTurretBase.cs#L2204
    --- Automerge ---
    @Timfa, Simply white listing your namespaces aren't enough to allow your methods into ingame scripting. Your mod and ingame programs have their own separate assemblies. Meaning even if your mod's namespaces were whitelisted, you still wouldn't be able to access them.
     
    Last edited by a moderator: Aug 18, 2016
  23. OniVe Trainee Engineer

    Messages:
    9
    Need a Getter to obtain the minimum and maximum property values.
    Something like this:
    Code:
    public interface IMyTerminalValueControl<TValue> : ITerminalProperty
    
    {
    	Func<IMyTerminalBlock, TValue> Getter { get; set; }
    	Action<IMyTerminalBlock, TValue> Setter { get; set; }
    
    	Func<IMyTerminalBlock, TValue> MinimumGetter { get; set; }
    	Func<IMyTerminalBlock, TValue> MaximumGetter { get; set; }
    }
    /* OR */
    public interface IMyTerminalControlProperty<TValue> : IMyTerminalControl, IMyTerminalValueControl<TValue>
    {
    	Func<IMyTerminalBlock, TValue> MinimumGetter { get; set; }
    	Func<IMyTerminalBlock, TValue> MaximumGetter { get; set; }
    }
    
    /* . . . */
    
    public class MyTerminalControlProperty<TBlock, TValue> : MyTerminalValueControl<TBlock, TValue>, IMyTerminalControlProperty<TValue>, IMyTerminalValueControl<TValue>
    	where TBlock : MyTerminalBlock
    {
    	public GetterDelegate MinimumGetter { get; set; }
    	public GetterDelegate MaximumGetter { get; set; }
    
    	public MyTerminalControlProperty(string id) : base(id)
    	{
    		Visible = (x) => false;
    	}
    
    	public override TValue GetDefaultValue(TBlock block)
    	{
    		return default(TValue);
    	}
    
    	public override TValue GetMinimum(TBlock block)
    	{
    		return MinimumGetter == null ? GetDefaultValue(block) : MinimumGetter(block);
    	}
    
    	public override TValue GetMaximum(TBlock block)
    	{
    		return MaximumGetter == null ? GetDefaultValue(block) : MaximumGetter(block);
    	}
    
    	protected override MyGuiControlBase CreateGui()
    	{
    		return null;
    	}
    }
     
    Last edited: Sep 4, 2016
  24. plaYer2k Master Engineer

    Messages:
    3,160
    Isnt
    Code:
    // Sandbox.ModAPI.Interfaces.ITerminalProperty<TValue>
    /// <summary>
    /// Maximum value of property (value from block definition)
    /// </summary>
    /// <param name="block">block reference</param>
    /// <returns>value of type <see cref="P:Sandbox.ModAPI.Interfaces.ITerminalProperty.TypeName" /></returns>
    TValue GetMaximum(IMyCubeBlock block);
    /// <summary>
    /// Minimum value of property (value from block definition)
    /// </summary>
    /// <param name="block">block reference</param>
    /// <returns>value of type <see cref="P:Sandbox.ModAPI.Interfaces.ITerminalProperty.TypeName" /></returns>
    TValue GetMinimum(IMyCubeBlock block);
    
    sufficient?
     
  25. OniVe Trainee Engineer

    Messages:
    9
    No.
    I'm talking about this:
    Code:
    var property = MyAPIGateway.TerminalControls.CreateProperty<TValue, TBlock>(id);
    property.SupportsMultipleBlocks = true;
    property.Getter = (block) => { /* Func */ };
    property.Setter = (block, value) => { /* Func */ };
    
    /* ??? */
    
    property.MininumGetter = (block) => { /* Func */ };
    property.MaximunGetter = (block) => { /* Func */ };
    
    --- Automerge ---
    Or add to white list "System.Activator", which is unlikely.
     
  26. Phoera Senior Engineer

    Messages:
    1,713
    this never will happen.(and how activator will help with Min/Max O_o?)
     
  27. OniVe Trainee Engineer

    Messages:
    9
    It clear, will not...
    But what I'm asking above realizable and does not violate the ideology.
     
  28. Phoera Senior Engineer

    Messages:
    1,713
    Keen, please add easy way to spawn missiles and projectiles.
    without playing with blocks.
    --- Automerge ---
    + add posilibility to get ammo info for missiles.
     
  29. midspace Senior Engineer

    Messages:
    2,224
    The new moddable fonts need their details accessible from the ModAPI, especially the Glyph information so we know what size an individual character is.
     
  30. padlina Trainee Engineer

    Messages:
    1
    Hello, would it be possible to have access to following:

    Code:
    MyFactionStateChange
    MyFactionCollection.FactionStateChanged
    This would allow some elegant event based faction modding (for example disabling leaving a faction).
     
Thread Status:
Not open for further replies.
This last post in this thread was made more than 31 days old.