Thread Status:
Not open for further replies.
  1. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    Another day, another programming language supported for plugins. Thanks to @bawNg, Oxide 2 now supports raw CSharp/C# plugins! This makes a wonderful addition to the languages already available (Lua, JavaScript, and Python) for plugins to developers to utilize. The .cs plugins are compiled on-the-fly from your plugins directory, and are only recompiled when changes are made to the plugin's source.

    Keep in mind that this is the initial release of Oxide.Ext.CSharp.dll, so there may be some issues and bugs to work out. There are still a good bit of changes planned for it, as well as a bit of cleanup to be done yet. If you'd like to test it out, just grab the latest download below and enjoy! You'll also need to have Microsoft .NET 3.5 x64 installed. If you have any problems, please let us know.

    Download: http://oxidemod.org/downloads/oxide-2-for-rust-experimental.714/

    I've also provided an example plugin below, courtesy of @bawNg.
    Code (C#):
    // Reference: Oxide.Ext.Rust
    // Reference: Newtonsoft.Json

    using System.Collections.Generic;
    using Newtonsoft.Json;

    namespace Oxide.Plugins
    {
        [Info("Sample Plugin", "bawNg", 0.1)]
        class SamplePlugin : RustPlugin
        {
            void Loaded()
            {
                var data = new Dictionary<string, string>() { { "Hello", "World" } };
                Puts("SamplePlugin made this: {0}", JsonConvert.SerializeObject(data));
            }

            void OnPlayerInit(BasePlayer new_player)
            {
                foreach (var player in BasePlayer.activePlayerList)
                    PrintToChat(player, "{0} has connected", new_player.displayName);
            }

            [ConsoleCommand("sample")]
            void cmdConsoleSample(ConsoleSystem.Arg arg)
            {
                SendReply(arg, "SamplePlugin: You typed 'sample' in console");
            }

            [ChatCommand("sample")]
            void cmdChatSample(BasePlayer player, string command, string[] args)
            {
                SendReply(player, "SamplePlugin: You typed /sample in chat");
            }
        }
    }
     
  2. bawNg

    bawNg Wood Hoarder Oxide Developer

    Change log for today's update, there are some breaking changes plugin developers need to be aware of.
    • Rust plugins must now be derived from RustPlugin instead of CSharpPlugin and need to reference Oxide.Ext.Rust
    • Magic comment references will now reference all references referenced by the reference
    • Refactored Rust specific helpers to RustPlugin base class in Oxide.Ext.Rust
    • Removed references to rust binaries from Oxide.Ext.CSharp
    • A plugin which failed to compile will no longer fail to recompile when reloaded
    • Plugins should be reloaded if their source is changed again during compilation
    • Fixed bug which caused an outdated version of plugins to be loaded after compilation
    • Added protection against rare race conditions which could cause IO exceptions
    • Compiler will now wait asynchronously until a script is no longer in use by another application
    • Improved error message when a plugins entry class does not match the plugins file name
    • Optimized compiler output buffering
    • Renamed CSharpPlugin custom attributes to avoid future name conflicts
     
    Hatemail and Wulf like this.
  3. Reneb

    Reneb Grenade Master Plugin Developer

    awesome :)
     
  4. Feramor

    Feramor Shack Builder Plugin Developer

    Code (Text):

    [1/29/2015 12:06:11 AM] [Oxide] 12:06 AM [Info] Polling plugin failed to compile! Exit code: 1
    [1/29/2015 12:06:11 AM] [Oxide] 12:06 AM [Info] Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.7903
    for Microsoft (R) .NET Framework version 3.5
    Copyright (C) Microsoft Corporation. All rights reserved.

    server\Feramor\oxide\plugins\Polling.cs(514,49): error CS1501: No overload for method 'Run' takes '1' arguments
    RustDedicated_Data\Managed\Facepunch.dll: (Location of symbol related to previous error)
    server\Feramor\oxide\plugins\Polling.cs(515,49): error CS1501: No overload for method 'Run' takes '1' arguments
    RustDedicated_Data\Managed\Facepunch.dll: (Location of symbol related to previous error)

    [1/29/2015 12:06:11 AM] [Oxide] 12:06 AM [Info] Plugin failed to compile: Polling (leaving previous version loaded)
     
    I'm getting this error on "ConsoleSystem.Run"

    Edit:Fixed error sorry for the post :)
     
    Last edited: Jan 28, 2015
  5. bawNg

    bawNg Wood Hoarder Oxide Developer

    Due to the way that Mono/Unity call methods, you cannot exclude optional arguments from method calls. In the case of a method which has a second argument that is optional, you need to pass null as that argument to be able to call the method.
     
  6. ownprox

    ownprox Shack Builder Plugin Developer

    best thing you could of ever done now im not limited by lua or js, i mainly programme in vc++ but i know c# very well your the best!
    --- Double Post Merged, Feb 1, 2015, Original Post Date: Jan 31, 2015 ---
    any reason i cant use system.io features
    Code (Text):
    [Oxide] 2:11 AM [Error] Buddies: UnauthorizedAccessException while calling Loade
    d: System access is restricted, you are not allowed to use System.IO.File
      at Oxide.Plugins.Buddies.Loaded () [0x00000] in <filename unknown>:0
      at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (ob
    ject,object[],System.Exception&)
      at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invoke
    Attr, System.Reflection.Binder binder, System.Object[] parameters, System.Global
    ization.CultureInfo culture) [0x00000] in <filename unknown>:0
     
  7. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    That's the sandbox. You won't be able to use those, as they are restricted to prevent malicious use. If you need access, you can always make an extension which aren't as widely accepted by hosts, but you shouldn't need to.
     
  8. ownprox

    ownprox Shack Builder Plugin Developer

    ok cool ill grab the latest source and yeah im using binaryreader and binarywriter to save and load data, do you know if the current method in oxide for saving/loading is as efficient as binaryreader/binarywriter
     
    Last edited: Feb 1, 2015
  9. dcode

    dcode Airdrop Stalker Server Owner Plugin Developer

    sorry, wrong thread :)
     
  10. bawNg

    bawNg Wood Hoarder Oxide Developer

    The only data storage supported by Oxide at the moment is JSON, you should try to use that short term if at all possible.

    I will be releasing protobuf based binary data storage support for C# plugins in the near future.
     
    ownprox likes this.
  11. ownprox

    ownprox Shack Builder Plugin Developer

    if yah need any help im a ledge at c#
     
  12. Reneb

    Reneb Grenade Master Plugin Developer

    ownprox in my AntiCheat i show how to use a data file.
    EDIT: Or in Jail
     
  13. ownprox

    ownprox Shack Builder Plugin Developer

    thanks i know how to use json i just know my method would be faster
    http://pastebin.com/X1dGP4SJ

    p.s can i get plugin developer title i released 2 plugins
     
    Last edited: Feb 2, 2015
  14. ColonelAngus

    ColonelAngus Wood Hoarder Plugin Developer

    Can we get an update to the 2010 compiler, so we can use the "dynamic" type?
     
  15. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    2010?
     
  16. ColonelAngus

    ColonelAngus Wood Hoarder Plugin Developer

  17. Feramor

    Feramor Shack Builder Plugin Developer

    Why dont you just use object class?
     
  18. bawNg

    bawNg Wood Hoarder Oxide Developer

    Unity 5 beta still relies on an old fork of Mono which does not support anything newer than .Net 3.5 unfortunately.
     
  19. ColonelAngus

    ColonelAngus Wood Hoarder Plugin Developer

    @Feramor dynamic is considerably easier to work with.

    @bawNg damn. Alright... Thanks.
     
  20. infused

    infused Scavenger

    Is there somewhere we can see what methods/functions/events exist to call?
     
Thread Status:
Not open for further replies.