Retrieving mods of a weapon

Snake

Moderator
Moderator
Jul 13, 2014
288
174
28
Well, I took a look at everything I could with @balu92 and we didn't find a way to.

Maybe anyone knows the answer ?
 

mikec

Master Of All That I Survey
Retired Staff
Trusted Member
Jul 12, 2014
296
152
28
Los Angeles, California, USA
C#:
public interface IHeldItem : IInventoryItem
The Interface for HeldItem extends the Interface for InventoryItem.

That means you will only find this IHeldItem object when a player is holding the item, which means you can find the mod attached through this object, only when the player is holding the weapon.

I know where it's located:
JavaScript:
function On_Command(PLayer, cmd, args) {
    if(cmd == "showmods") {
        var itemmods = Player.Inventory.InternalInventory.activeItem.itemMods;
        for(var i=0; i < itemmods.length; i++) {
            Player.Message("Mod" + i + ": " + itemmods[i].name);
        }
    }
}
 
  • Useful
Reactions: CorrosionX

Snake

Moderator
Moderator
Jul 13, 2014
288
174
28
C#:
public interface IHeldItem : IInventoryItem
The Interface for HeldItem extends the Interface for InventoryItem.

That means you will only find this IHeldItem object when a player is holding the item, which means you can find the mod attached through this object, only when the player is holding the weapon.

I know where it's located:
JavaScript:
function On_Command(PLayer, cmd, args) {
    if(cmd == "showmods") {
        var itemmods = Player.Inventory.InternalInventory.activeItem.itemMods;
        for(var i=0; i < itemmods.length; i++) {
            Player.Message("Mod" + i + ": " + itemmods[i].name);
        }
    }
}
Only in the active item ? And there's no way in the world to get the mods from the others ? That's a shame :C
 

balu92

Retired Staff
Retired Staff
Trusted Member
Jul 11, 2014
338
75
28
34
At runtime(with jint, magma, ironpython), you can get it for any weapon, but at compile time you would need to cast the IInventoryItems to a type of: BulletWeaponDataBlock+ITEM_TYPE...
 

Snake

Moderator
Moderator
Jul 13, 2014
288
174
28
At runtime(with jint, magma, ironpython), you can get it for any weapon, but at compile time you would need to cast the IInventoryItems to a type of: BulletWeaponDataBlock+ITEM_TYPE...
How can we ?
 

balu92

Retired Staff
Retired Staff
Trusted Member
Jul 11, 2014
338
75
28
34
JavaScript:
function On_Command(Player, cmd, args) {
    if(cmd == "showmods") {
        var items = Player.Inventory.Items;
        var barItems = Player.Inventory.BarItems;
        var imods;
        for(var i=0; i < items.Length; i++) {
            try { imods = items[i].RInventoryItem.itemMods; } catch (ignore) { }
            for(var j = 0; j < imods.Length; j++) {
                if(imods[j].name != null) UnityEngine.Debug.Log(items[i].Name + " has " + imods[j].name);
            }
        }
        for(var k=0; k < barItems.Length; k++) {
            try { imods = barItems[k].RInventoryItem.itemMods; } catch (ignore) { }
            for(var l = 0; l < imods.Length; l++) {
                if(imods[l].name != null) UnityEngine.Debug.Log(barItems[k].Name + " has " + imods[l].name);
            }
        }
    }
}
INI:
[DEBUG] [CHAT-CMD] "Balu" executed "/showmods"
M4 has Flashlight Mod
M4 has Holo sight
M4 has Silencer
M4 has Laser Sight
Bolt Action Rifle has Laser Sight
Bolt Action Rifle has Holo sight
Bolt Action Rifle has Flashlight Mod
Bolt Action Rifle has Silencer
9mm Pistol has Silencer
9mm Pistol has Flashlight Mod
9mm Pistol has Holo sight
9mm Pistol has Laser Sight
Shotgun has Silencer
Shotgun has Holo sight
Shotgun has Flashlight Mod
 
Last edited:
  • Like
Reactions: Snake and mikec

Snake

Moderator
Moderator
Jul 13, 2014
288
174
28
JavaScript:
function On_Command(Player, cmd, args) {
    if(cmd == "showmods") {
        var items = Player.Inventory.Items;
        var barItems = Player.Inventory.BarItems;
        var imods;
        for(var i=0; i < items.Length; i++) {
            try { imods = items[i].RInventoryItem.itemMods; } catch (ignore) { }
            for(var j = 0; j < imods.Length; j++) {
                if(imods[j].name != null) UnityEngine.Debug.Log(items[i].Name + " has " + imods[j].name);
            }
        }
        for(var k=0; k < barItems.Length; k++) {
            try { imods = barItems[k].RInventoryItem.itemMods; } catch (ignore) { }
            for(var l = 0; l < imods.Length; l++) {
                if(imods[l].name != null) UnityEngine.Debug.Log(barItems[k].Name + " has " + imods[l].name);
            }
        }
    }
}
INI:
[DEBUG] [CHAT-CMD] "Balu" executed "/showmods"
M4 has Flashlight Mod
M4 has Holo sight
M4 has Silencer
M4 has Laser Sight
Bolt Action Rifle has Laser Sight
Bolt Action Rifle has Holo sight
Bolt Action Rifle has Flashlight Mod
Bolt Action Rifle has Silencer
9mm Pistol has Silencer
9mm Pistol has Flashlight Mod
9mm Pistol has Holo sight
9mm Pistol has Laser Sight
Shotgun has Silencer
Shotgun has Holo sight
Shotgun has Flashlight Mod
No wayyyyyyy ! You are a genius !! I'm gonna test this out right now.
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,095
4,815
113
At your house.
github.com
JavaScript:
function On_Command(Player, cmd, args) {
    if(cmd == "showmods") {
        var items = Player.Inventory.Items;
        var barItems = Player.Inventory.BarItems;
        var imods;
        for(var i=0; i < items.Length; i++) {
            try { imods = items[i].RInventoryItem.itemMods; } catch (ignore) { }
            for(var j = 0; j < imods.Length; j++) {
                if(imods[j].name != null) UnityEngine.Debug.Log(items[i].Name + " has " + imods[j].name);
            }
        }
        for(var k=0; k < barItems.Length; k++) {
            try { imods = barItems[k].RInventoryItem.itemMods; } catch (ignore) { }
            for(var l = 0; l < imods.Length; l++) {
                if(imods[l].name != null) UnityEngine.Debug.Log(barItems[k].Name + " has " + imods[l].name);
            }
        }
    }
}
INI:
[DEBUG] [CHAT-CMD] "Balu" executed "/showmods"
M4 has Flashlight Mod
M4 has Holo sight
M4 has Silencer
M4 has Laser Sight
Bolt Action Rifle has Laser Sight
Bolt Action Rifle has Holo sight
Bolt Action Rifle has Flashlight Mod
Bolt Action Rifle has Silencer
9mm Pistol has Silencer
9mm Pistol has Flashlight Mod
9mm Pistol has Holo sight
9mm Pistol has Laser Sight
Shotgun has Silencer
Shotgun has Holo sight
Shotgun has Flashlight Mod
Do a pull req with C# code. You may want to create a method like that in the Util, or in the Inv class
 

balu92

Retired Staff
Retired Staff
Trusted Member
Jul 11, 2014
338
75
28
34
Do a pull req with C# code. You may want to create a method like that in the Util, or in the Inv class
that's what I'm talking about:
At runtime(with jint, magma, ironpython), you can get it for any weapon, but at compile time you would need to cast the IInventoryItems to a type of: BulletWeaponDataBlock+ITEM_TYPE...
'ITEM_TYPE' is a private sealed class in BulletWeaponDataBlock, I don't know how to cast to that type at compile time
 

mikec

Master Of All That I Survey
Retired Staff
Trusted Member
Jul 12, 2014
296
152
28
Los Angeles, California, USA
JavaScript:
function On_Command(Player, cmd, args) {
    if(cmd == "showmods") {
        var type;
        Util.TryFindType("SaveableInventory");
        var saveable = UnityEngine.Object.FindObjectsOfType(type);
        var imods;

        for(var i=0; i < saveable.Length; i++) {
            // ?
        }            
    }
}
 

mikec

Master Of All That I Survey
Retired Staff
Trusted Member
Jul 12, 2014
296
152
28
Los Angeles, California, USA
that's what I'm talking about:

'ITEM_TYPE' is a private sealed class in BulletWeaponDataBlock, I don't know how to cast to that type at compile time
You must patch the assembly to make it public, same as was done for all the private fields we need to access.
 

balu92

Retired Staff
Retired Staff
Trusted Member
Jul 11, 2014
338
75
28
34
JavaScript:
function On_Command(Player, cmd, args) {
    if(cmd == "showmods") {
        var type;
        Util.TryFindType("SaveableInventory");
        var saveable = UnityEngine.Object.FindObjectsOfType(type);
        var imods;

        for(var i=0; i < saveable.Length; i++) {
            // ?
        }           
    }
}
Util.TryFindType("SaveableInventory", type);
 

balu92

Retired Staff
Retired Staff
Trusted Member
Jul 11, 2014
338
75
28
34
(didn't tested, but should work)
JavaScript:
function On_Command(Player, cmd, args) {
    if(cmd == "showmods") {
        var type;
        Util.TryFindType("SaveableInventory", type);
    //    var type = Util.TryFindReturnType("SaveableInventory");
        var saveables = UnityEngine.Object.FindObjectsOfType(type);
        var imods;
        var currentItem;

        for(var i=0; i < saveables.Length; i++) {
            for(var j = 0; j < saveables[i].slotCount; j++) {
                if(saveables[i].GetItem(j, currentItem)) {
                    try { imods = currentItem.itemMods; } catch (ignore) { }
                    for(var l = 0; l < imods.Length; l++) {
                        if(imods[l].name != null) UnityEngine.Debug.Log(currentItem.datablock.name + " has " + imods[l].name);
                    }
                }
            }
        }
    }
}
 

balu92

Retired Staff
Retired Staff
Trusted Member
Jul 11, 2014
338
75
28
34
You must patch the assembly to make it public, same as was done for all the private fields we need to access.
I tried quite a few things by now, no luck. I will try to gather some cecil doc on that tomorrow.
 

CorrosionX

Plugin Developer
Plugin Developer
Sep 3, 2014
212
86
18
California
Just wanted to say THANKS, using idea's and code from this topic, figured out how to set unlimited ammo without having to add ammo to inv! Woot! Will be in my Unlimited Ammo plugin I'm working on. (currently not added yet) :)
 
  • Like
Reactions: Snake