Fougerite Official

Fougerite Official 1.9.7

No permission to download
  • Screwed the Airdrop event. It's static void, I need to look in It. Repatch. For now I disabled the call of the event.
WARNING. The new source was built on the last release of Rust Legacy Server. (May 01)

Those who had Fougerite installed already, get a fresh Assembly dll file, and use the patcher.


First of all I would like to thank @mikec for keeping up with the last improvements and modifications. Two days ago I started patching, and I received the basic knowlegde from @balu92 and I added a bunch of events.
I made some tweaks / improvements / API additions. I will give you a list below. I might have forgotten some things, I'm concentrating not to forget anything.

Just to clarify at the beginning: Source was moved here.

Engine Modifications:
Jint:
Jint received the reload commands similar to py engine.
jint.load PluginName
jint.unload PluginName
jint.reload PluginName
jint.reload
Magma:
Same for magma:
magma.load PluginName
magma.unload PluginName
magma.reload PluginName
magma.reload
RustPP:
  • /tpto x y z - New command for coords ( I didn't test It :O )
  • Guess what we have here. I added some access to the RustPP API. Which you can Reach at Server.GetRustPPAPI() You can access admins/friends from there. It leads here.
  • I added a Player.Moderator property. It checks if the player has the flag called Moderator (Yea plugin devs, be happy.)
Fougerite:
I made some safety mechanisms. If you use Plugin.Log and It reaches 1 mb file size, It will be renamed, so It won't cause writing lags. (I'm sure It could take more, but I wanted It smooth.)

Same for inis, but they are limited to 0.65 mb and they won't get removed. The Server will just log that you should delete the file.

Global Ini file for banlist:
Server.GlobalBanList

New Hooks:

Navmesh
No, I didn't make a plugin hook for this, only for fougerite. If anyone requests It, I may do It. The purpose of this event was to kill the bugged animals. No more messages like that.
ReceiveNetwork
I made this hook only for CSharp users. Same for this thing, anybody wants this in Py or Js plugins I can do It. But I think this hook won't be used at all. The purpose of this event was to bypass players sending wrong Metabolism properties, causing crash/using hacks.
PlayerTeleport
This hook is for everyone. It gets called when somebody teleports (Uses Fougerite Teleport function) Just incase I'm planning to patch Rust It self, so we can detect all teleportation calls. (Maybe hacks too?)

Python:
def On_PlayerTeleport(self, Player, Vector3From, Vector3To):
    Server.Broadcast(Player.Name + " teleported!")
JavaScript:
function On_PlayerTeleport(Player, Vector3From, Vector3To)
{
    Server.Broadcast(Player.Name + " teleported!");
}
CraftingEvent
Old users were waiting for this a lot since Magma. Now It's here.
Parameter class

Python:
def On_Crafting(self, CraftingEvent):
        CraftingEvent.Player.Message("Time: " + str(CraftingEvent.LastWorkBenchTime))
        if not CraftingEvent.IsLegit:
            Server.Broadcast(CraftingEvent.Player.Name + " is crafting something that he doesn't have!")
            Server.Broadcast("What a n00b hacker!")
            #CraftingEvent.Cancel() - Fougerite cancels the hook by default If It's not legit.
            #CraftingEvent.Player.Disconnect() - Fougerite bans the player automatically
JavaScript:
function On_Crafting(CraftingEvent)
{
    CraftingEvent.Player.Message("Time: " + CraftingEvent.LastWorkBenchTime);
    if (!CraftingEvent.IsLegit)
    {
        Server.Broadcast(CraftingEvent.Player.Name + " is crafting something that he doesn't have!");
        Server.Broadcast("What a n00b hacker!");
        //CraftingEvent.Cancel(); - Fougerite cancels the hook by default If It's not legit.
        //CraftingEvent.Player.Disconnect(); - Fougerite bans the player automatically
    }
}
ResourceSpawn
Called when resource is spawned.
Has a rust parameter, nothing serious.

Python:
def On_ResourceSpawn(self, ResourceTarget):
    Server.Broadcast("Type: " + str(ResourceTarget))
JavaScript:
function On_ResourceSpawn(ResourceTarget)
{
    Server.Broadcast("Type: " + ResourceTarget);
}
ItemAdded
Yaheee. Called when an item is added to an inventory.
(Untested, haha, but should work.)
Parameter class

Python:
def On_ItemAdded(self, InventoryModEvent):
    player = InventoryModEvent.Player # Can be null if he is offline, watch it.
    netuser = InventoryModEvent.NetUser
    item = InventoryModEvent.Item # returns fougerite item https://github.com/dretax/DX-Fougerite/blob/master/Fougerite/Fougerite/EntityItem.cs
    item2 = InventoryModEvent.InventoryItem # returns rust item
    inv = InventoryModEvent.Inventory # returns rust inventory
    inv2 = InventoryModEvent.FInventory # returns fougerite inventory https://github.com/dretax/DX-Fougerite/blob/master/Fougerite/Fougerite/FInventory.cs
    slot = InventoryModEvent.Slot
JavaScript:
function On_ItemAdded(self, InventoryModEvent)
{
    var player = InventoryModEvent.Player; // Can be null if he is offline, watch it.
    var netuser = InventoryModEvent.NetUser;
    var item = InventoryModEvent.Item; // returns fougerite item https://github.com/dretax/DX-Fougerite/blob/master/Fougerite/Fougerite/EntityItem.cs
    var item2 = InventoryModEvent.InventoryItem; // returns rust item
    var inv = InventoryModEvent.Inventory; // returns rust inventory
    var inv2 = InventoryModEvent.FInventory; // returns fougerite inventory https://github.com/dretax/DX-Fougerite/blob/master/Fougerite/Fougerite/FInventory.cs
    var slot = InventoryModEvent.Slot;
}
ItemRemoved
Same parameter, same properties, different event.

Python:
def On_ItemRemoved(self, InventoryModEvent):
    player = InventoryModEvent.Player # Can be null if he is offline, watch it.
    netuser = InventoryModEvent.NetUser
    item = InventoryModEvent.Item # returns fougerite item https://github.com/dretax/DX-Fougerite/blob/master/Fougerite/Fougerite/EntityItem.cs
    item2 = InventoryModEvent.InventoryItem # returns rust item
    inv = InventoryModEvent.Inventory # returns rust inventory
    inv2 = InventoryModEvent.FInventory # returns fougerite inventory https://github.com/dretax/DX-Fougerite/blob/master/Fougerite/Fougerite/FInventory.cs
    slot = InventoryModEvent.Slot
JavaScript:
function On_ItemRemoved(self, InventoryModEvent)
{
    var player = InventoryModEvent.Player; // Can be null if he is offline, watch it.
    var netuser = InventoryModEvent.NetUser;
    var item = InventoryModEvent.Item; // returns fougerite item https://github.com/dretax/DX-Fougerite/blob/master/Fougerite/Fougerite/EntityItem.cs
    var item2 = InventoryModEvent.InventoryItem; // returns rust item
    var inv = InventoryModEvent.Inventory; // returns rust inventory
    var inv2 = InventoryModEvent.FInventory; // returns fougerite inventory https://github.com/dretax/DX-Fougerite/blob/master/Fougerite/Fougerite/FInventory.cs
    var slot = InventoryModEvent.Slot;
}
Airdrop
Called when airdrop is coming. Has a location parameter.

Python:
def On_Airdrop(self, Vector3):
    Server.Broadcast("Airdrop inbound to: " + str(Vector3))
JavaScript:
function On_Airdrop(Vector3)
{
    Server.Broadcast("Airdrop inbound to: " + Vector3);
}
Hopefully I covered them all, but I'm sure I missed some other stuffs out.
I'm gonna be adding 2-3 new hooks too later.
  • Just realised that the modification I made in disconnect event doesn't let you to use the properties of the player, so this fix will work for It. (Removing player from Server.Players after I called all the disconnect hooks)
  • HurtEvent now detects Radiation suicide hack, and bypasses It
  • Sleeper property got a Destroy() function (UnTested)
  • RustPP's /addadmin command was fixed
  • Fixed IsOnline property, now It works 100%
  • Added IsOnline check to Player.AdjustPoisonLevel
  • Server.Cache and OnConnected event tweaks
  • Util.GetDooratCoords and Util.GetEntityatCoords fixes
  • Most of the Hooks are now taking the player out of the Server.Cache instead of doing a for cycle or a Query to find the player (Only PlayerGathering doesn't use It yet.)
  • GlitchFix got some tweaks
  • HurtEvent weapon fixes.
  • GlitchFix should detect Small loot stacks in the pillars.

Player property got some new stuffs:
C#:
        public bool HasBlueprint(BlueprintDataBlock dataBlock)
        {
            if (this.IsOnline)
            {
                PlayerInventory invent = this.Inventory.InternalInventory as PlayerInventory;
                if (invent.KnowsBP(dataBlock))
                {
                    return true;
                }
            }
            return false;
        }

        public bool HasBlueprint(string name)
        {
            if (this.IsOnline)
            {
                foreach (BlueprintDataBlock blueprintDataBlock in this.Blueprints())
                {
                    if (name.ToLower().Equals(blueprintDataBlock.name.ToLower()))
                    {
                        return true;
                    }
                }
            }
            return false;
        }

        public ICollection<BlueprintDataBlock> Blueprints()
        {
            if (!this.IsOnline)
            {
                return null;
            }
            PlayerInventory invent = this.Inventory.InternalInventory as PlayerInventory;
            ICollection<BlueprintDataBlock> collection = new List<BlueprintDataBlock>();
            foreach (BlueprintDataBlock blueprintDataBlock in invent.GetBoundBPs())
            {
                collection.Add(blueprintDataBlock);
            }
            return collection;
        }
  • HurtEvent weapon fixes.
  • GlitchFix should detect Small loot stacks in the pillars.

Player property got some new stuffs:
C#:
        public bool HasBlueprint(BlueprintDataBlock dataBlock)
        {
            if (this.IsOnline)
            {
                PlayerInventory invent = this.Inventory.InternalInventory as PlayerInventory;
                if (invent.KnowsBP(dataBlock))
                {
                    return true;
                }
            }
            return false;
        }

        public bool HasBlueprint(string name)
        {
            if (this.IsOnline)
            {
                foreach (BlueprintDataBlock blueprintDataBlock in this.Blueprints())
                {
                    if (name.ToLower().Equals(blueprintDataBlock.name.ToLower()))
                    {
                        return true;
                    }
                }
            }
            return false;
        }

        public ICollection<BlueprintDataBlock> Blueprints()
        {
            if (!this.IsOnline)
            {
                return null;
            }
            PlayerInventory invent = this.Inventory.InternalInventory as PlayerInventory;
            ICollection<BlueprintDataBlock> collection = new List<BlueprintDataBlock>();
            foreach (BlueprintDataBlock blueprintDataBlock in invent.GetBoundBPs())
            {
                collection.Add(blueprintDataBlock);
            }
            return collection;
        }
  • Alright guys. For the first time i was able to catch the problem. OnDisconnected event didn't get executed sometimes. Since It had try catch It didn't print anything. I added a log debug message just for safety there. To fix this problem I had to modify Rust++, since that caused the error. OnDisconnect event now uses Server.Cache to avoid null exception errors. Update RustPP.dll and Fougerite.dll
  • As far as I have seen the players who had stranger names no longer have it. Turned out mike's player property updater works weird. I don't use that ,instead of that I now remove and re-add the player on connection to the cache. Should be working alright.
Sleeper object:
C#:
        public DeployableObject Object
        {
            get { return this._sleeper; }
        }

        public string OwnerID
        {
            get { return Object.ownerID.ToString(); }
        }

        public string OwnerName
        {
            get { return Object.ownerName; }
        }

        public Vector3 Location
        {
            get { return Object.transform.position; }
        }

        public float X
        {
            get { return Object.transform.position.x; }
        }

        public float Y
        {
            get { return Object.transform.position.y; }
        }

        public float Z
        {
            get { return Object.transform.position.z; }
        }

        public int InstanceID
        {
            get
            {
                return Object.GetInstanceID();
            }
        }
  • Fixed onconnection bugs
  • Added Mike's invention. Player.Cache. But instead of adding It to the player class I added It to Server class. Server.Cache is a Dictionary and gets updated on every connection, and stores players.
    C#:
    public static IDictionary<ulong, Fougerite.Player> Cache = new Dictionary<ulong, Fougerite.Player>();
    This Dictionary stores every player with his SteamID. Doing
    Code:
    Server.Cache[Player.UID]
    
    //OR
    
    Server.Cache[long(Player.SteamID)]
    Will return you the Player class. From that, you can access the Player's Structures, and all his entities. This method allows you to access player properties even if he is offline. Using this will not only make your code faster, but also ensures that you will not get null player properties back. However, you can't do a lot of things if the Player is offline, Fougerite won't let you send him anything due to the last update's IsOnline check, which hopefully bypasses RPC errors. Using the following properties are safe at any time:
    Code:
    Player.UID
    Player.GameID
    Player.SteamID
    Player.IP
    Player.Name
    Player.Sleeper
    Player.AtHome
    Player.Structures
    Player.Deployables
    Player.Shelters
    Player.Storage
    Player.Sleeper.Location
    Player.Fires
    I plan to create a class for the Sleeper myself which will handle most of the properties for the Player.Sleeper. But for now It stays Entity.
  • I modified the Timer Elapsed Event. I saw that FAC no longer causes RPC crash logs, but still causes Timer crash logs. I made a try catch, and the timer will log the error, and also tries to restart the timer if there was any error. Please test this. Keep looking at the logs.
  • Player properties were modified and Player.Sleeper added
  • @MasterPeace I'm now logging the player IP on connection.
I think That's what I did. More to come later.