Jessecar96 / SteamBot

Automated bot software for interacting with Steam Trade
http://scrap.tf
MIT License
1.33k stars 911 forks source link

Support for multiple item schemas #105

Open coffman34 opened 11 years ago

coffman34 commented 11 years ago

I was interested in using the bot for Dota 2 item trading. But, I assume the item details are different between the two games, and it is causing the bot to crash when a non-TF2 item is added to the trade window.

The errors given are:

ERROR: Error Polling Trade: System.NullReferenceException: Object reference not set to an instance of an object.
at .......\Trade.cs:line 541
at SteamBot.Bot.<.ctor>b__2() in c:\..........\Bot.cs:line 132
coffman34 commented 11 years ago

I think I accidently closed the issue. I have confirmed the bug with the scrap.tf bots as well.

teliosdev commented 11 years ago

The scrap.tf bots were forked from SteamBot early in SteamBot's development, so we really can't say much for scrap.tf.

coffman34 commented 11 years ago

Well, What I was thinking, since it appears to be in both bots, that's it's a problem with the core code, and not some change that was made, or, not made.

Since you say they were forked from an earlier build, it would seem like this issue would be something that is has been there for a while, but hasn't shown itself since no one has attempted to use other items with it.

teliosdev commented 11 years ago

I think when it tries to get the item from the item schema, it doesn't exist so it throws that sort of general error (from looking at line 541 of Trade.cs).

coffman34 commented 11 years ago

I have been looking at the Schema.cs file, and it appears to only call the TF2 item schema. This could be why we are experiencing crashes from the bot. I have adjusted the Game ID in the API call to call from Dota 2 instead. This still throws errors when a Dota item is dropped in the trade window. I am going to start looking at the item structure to see what the difference is.

EDIT: I believe I have found where the error is occuring. Currently in Schema.cs items are returned by a given crafting material. In the return results from the API call to the Dota item schema, there is no property for CraftMaterialType.

Here is a sample of an item returned from the Dota schema.

        {
        "name": "Riki's Dagger",
        "defindex": 0,
        "item_class": "dota_item_wearable",
        "item_type_name": "#DOTA_WearableType_Daggers",
        "item_name": "#DOTA_Item_Rikis_Dagger",
        "proper_name": false,
        "item_quality": 0,
        "image_inventory": null,
        "min_ilevel": 1,
        "max_ilevel": 1,
        "image_url": "",
        "image_url_large": "",
        "capabilities": {
                "can_craft_mark": true,
                "can_be_restored": true,
                "strange_parts": true,
                "paintable_unusual": true
        }
    }
teliosdev commented 11 years ago

The problem with supporting both TF2 and Dota is the time it would take to request both schemas. Maybe if we have options for each bot, like download/use the TF2, Dota, or both schemas? And if the user adds an item that doesn't exist, gracefully handle it instead of throwing an exception.

coffman34 commented 11 years ago

I was able to figure out why the errors were throwing. There are 2 calls to the Schema Web API. Once both calls were changed to access the Dota schema, adding items from Dota now works as expected. I am fine with having the owner of the bot set up the script calls for which game they want, until we can figure out a long term solution to using both.

Problem is, the name of the project is SteamBot, not TF2Bot. Therefore we need to make it a goal to work on all steam trading. I will head up the Dota branch. I have been unable to figure out the schema for the Steam Inventory, ie. games, beta invites, etc. So I am not for sure that it is possible yet.

We could add a option in the settings file, that allows the user to place in the ID of the game they wish to use. 440 for TF2, 570 for Dota 2. All it would require is adding of the parameter, then building the new API calls to use the variable instead of a hard coded address.

teliosdev commented 11 years ago

What I'm thinking is to define a setting in the file that is an array of IDs to use for games. For example:

{
    "SchemaGames": [440, 570],
}

Obviously, "SchemaGames" wouldn't exactly be the key for it, but at least we would be able to support multiple games. And it wouldn't be hard to check up on trading, since we could open a trade in a regular browser and check requests using any tools.

coffman34 commented 11 years ago

There are a few other places where the GameID comes in to play. Such as in Trade.cs when adding/removing items. The appid has to be set to the correct id to make sure that it doesn't crash and give the error above.

I have been able to get the bot working with Dota 2 items, however, same as when it's set in TF2 mode, it can only trade Dota 2 items.

I am not sure we can get around fetching both schemas. And I'm not for sure how we would deal with defindexes being the same for the 2 different items.

cwhelchel commented 11 years ago

The problem with supporting both TF2 and Dota is the time it would take to request both schemas.

@redjazz96 If we could cache the schemas (#103) this would be less of a hindrance.

teliosdev commented 11 years ago

@cwhelchel yeah, that might work

StormReaper commented 11 years ago

I'm just curious where does one find the data that steam provides with the trade? Does it not include the information on what item belongs to which game? Because as i see it right now even if you cache both schemas you will only be able to use one or the other because they have overlapping defindexes? Also can the bot be fooled into trading the wrong item at the moment? i.e dota2 and tf2 items with same defindex?

Philipp15b commented 11 years ago

@StormReaper For every event that you get from tradestatus, there is an appid sent with it.

94m3k1n9 commented 11 years ago

@StormReaper the problem isn't that there are overlapping defindexes, the problem is that there are no defindexes at all.

StormReaper commented 11 years ago

So i've been digging around to see if there might be a way around this, there are allready methods in place for fetching the tf2 inventory community feed which return some data, the defindex is not present but a different one is there which can be used as a unique id for a schema.

There are also other community feeds for other games and gifts, the biggest problem though is that there is no schemas for all this data.

The bot would need some sort of an external schema to be built for handling these items, tf2 and other valve games could have the schemas matched by some variables such as name, or picture not ideal but I believe it could work. Steam must have its own shema for the steam inventory but its unclear if or when they would release this info. Sorry if this sounds slightly confusing i'll try to clarify as best I can later and hopefully code this in soon.

StormReaper commented 11 years ago

A small update on my last comment, I've made some new and interesting discoveries most importantly of which is that we should be able to get the bot working with private backpack/inventories. There are two methods (foreigninventory) and (inventory) on the community website that can be used while inside a trade to fetch the inventory of the other user and the bot. I've found these methods while observing a steam trade with fiddler and one is executed when the trade is loaded to fetch the users backpack, and the other is executed once the other user adds an item.

Both of these methods return a list of data about each inventory item including a classid which is unique and is used to identify items in a schema. For valve games the classid can be further used in ISteamEconomy/GetAssetPrices and ISteamEconomy/GetAssetPrices SteamWebAPI calls to get more data, the GetAssetPrices also includes defindex to classid mapping so we can use that to map with the currently used GetSchema methods and other schemas for dota2 and portal2? haven't checked yet but most likely.

For non valve games such Spiral Knights, SMNC and Crimecraft gangwars there are currently no schemas that can be fetched. But each inventory item still comes with enough data to identify the items.

I've already mapped a few classes and webapi calls, but could use some help especially interested in the web methods used for the trade and the way cookies are currently handled.

awillinger commented 11 years ago

Any Updates with this?

StormReaper commented 11 years ago

I kinda stopped working on it, although what i said is possible, the asset prices only contain the defindex definitions for items that can be sold through the store, so quite a number of items are missing i.e crates, promos etc. Also it's quite a lot harder to find certain information like item attributes, because they are stored differently for easy use in the steam trade window.

It would require significant work to be done to fetch all the item attributes if you want them. Although probably the best single example of this working in action is the the tf2 warehouse bot. As it doesn't rely on the tf2 web api to fetch the backpacks. I'm currently busy with other work so i'm not going to be doing any other work with this for now, but perhaps in the future.

awillinger commented 11 years ago

Is there atleast a way to the the other User's Steam Gifts Inventory?

There is a sorta-of public API:

http://steamcommunity.com/id/%profilename%/inventory/json/753/

StormReaper commented 11 years ago

Yes, its pretty similar to the one you posted have a look at GetForeignInventory method on this https://github.com/StormReaper/SteamBot/blob/steam/SteamTrade/TradeSession.cs

teliosdev commented 11 years ago

Is this still an issue?

waylaidwanderer commented 11 years ago

Looks like an interesting discussion. If we could get SteamBot to work with multiple games that would be pretty great.

ausey00 commented 11 years ago

+1 for multiple game support, or the support of steam inventory items, such as trading cards.

TheAnthonyNL commented 11 years ago

Would like to see an update on this too.

enthdegree commented 11 years ago

Where is the exception thrown? Bot.cs?

It looks like whatever exception it causes is caught and thrown away because during debug I added a non-TF2 item and the window closed without ever entering my OnAddItem() routine.

remco138 commented 11 years ago

Would love to see support for steam inventory, my main reason of interest for this project

Lagg commented 11 years ago

If someone is actually wanting to look into this you may be able to glean some useful information from steamodd's sim module.

glen-84 commented 10 years ago

In OnTradeAddItem(), when adding a Dota 2 item, schemaItem is NULL and inventoryItem contains no useful information – does this mean that SteamBot does not support Dota 2 trading?

coffman34 commented 10 years ago

No, Steambot supports Dota 2 trading. However, there are some changes that need to be made to some of the code to make it work. I would suggest reading through some of the past posts. Your answer is in there.

On Mon, Apr 7, 2014 at 7:24 AM, glen-84 notifications@github.com wrote:

In OnTradeAddItem(), when adding a Dota 2 item, schemaItem is NULL and inventoryItem contains no useful information - does this mean that SteamBot does not support Dota 2 trading?

Reply to this email directly or view it on GitHubhttps://github.com/Jessecar96/SteamBot/issues/105#issuecomment-39719093 .

zuiahve commented 10 years ago

"No, Steambot supports Dota 2 trading. However, there are some changes that need to be made to some of the code to make it work. I would suggest reading through some of the past posts. Your answer is in there."

I just trade with one user who use steam bot for dota2.. he trade rares, keys..

coffman34 commented 10 years ago

What are you talking about? I didn't say it couldn't be done. I said it can be done, but you have to read the past posts on how to get Steambot setup correctly to do it.

On Sun, Jun 29, 2014 at 3:48 AM, zuiahve notifications@github.com wrote:

"No, Steambot supports Dota 2 trading. However, there are some changes that need to be made to some of the code to make it work. I would suggest reading through some of the past posts. Your answer is in there."

I just trade with one user who use steam bot for dota2.. he trade rares, keys..

— Reply to this email directly or view it on GitHub https://github.com/Jessecar96/SteamBot/issues/105#issuecomment-47448112.