SteamRE / SteamKit

SteamKit2 is a .NET library designed to interoperate with Valve's Steam network. It aims to provide a simple, yet extensible, interface to perform various actions on the network.
GNU Lesser General Public License v2.1
2.59k stars 495 forks source link

Sending GC Message. Object reference not set to an instance of an object. #306

Closed Logxn closed 8 years ago

Logxn commented 8 years ago

I need to say im very nooby with protobuffs. I looked trough the DOTA2 Example to try to understand whats happening and how its done. But they way I try to commend a guy on csgo is not quite working the way I thought it would :D

`static void OnClientWelcome(IPacketGCMsg packetMsg) { SteamID steamID = new SteamID(); uint input; var msg = new ClientGCMsgProtobuf(packetMsg);

       Console.WriteLine();
       Console.WriteLine("> The GC is welcoming us. {0}", msg.Body.version);

       var requestCommend = new ClientGCMsgProtobuf<CMsgGCCStrike15_v2_ClientCommendPlayer>((uint)ECsgoGCMsg.k_EMsgGCCStrike15_v2_ClientCommendPlayer);

       uint.TryParse("76561198312797851", out input);

       requestCommend.Body.account_id = input;
       requestCommend.Body.match_id = 8;
       requestCommend.Body.commendation.cmd_teaching = 1;
       requestCommend.Body.commendation.cmd_leader = 4;
       requestCommend.Body.commendation.cmd_teaching = 2;

       gameCoordinator.Send(requestCommend, CSGOID);
   }`

I am sorry for the poorly coding :D Well it shows me that "cmd_teaching" => Object reference not set to an instance of an object. What am I doing wrong?

Netshroud commented 8 years ago

requestComment.commentation is probably null. You'll need to create a commendation object and assign it to the property.

Logxn commented 8 years ago

Can you show me how to do that properly?

Netshroud commented 8 years ago

requestComment.commentation = new CMsgGCCStrike15_v2_Whatever_Type_Goes_Here();

Logxn commented 8 years ago

requestCommend.Body.commendation = new CMsgGCCStrike15_v2_ClientCommendPlayer();

=>Cannot implicitly convert type 'SteamKit2.GC.CSGO.Internal.CMsgGCCStrike15_v2_ClientCommendPlayer' to 'SteamKit2.GC.CSGO.Internal.PlayerCommendationInfo'

Netshroud commented 8 years ago

Then you have the wrong type for CMsgGCCStrike15_v2_Whatever_Type_Goes_Here.

The compiler is telling you what type it expect. Listen to it.

rossengeorgiev commented 8 years ago

Also the values appear to be incorrect. See the types for the protobuf message. Ideally capture the message with nethook to see what message and values are sent.

Logxn commented 8 years ago

requestCommend.Body.commendation = new SteamKit2.GC.CSGO.Internal.PlayerCommendationInfo();
requestCommend.Body.account_id = input; requestCommend.Body.match_id = 8; requestCommend.Body.commendation.cmd_friendly = 1; requestCommend.Body.commendation.cmd_leader = 4; requestCommend.Body.commendation.cmd_teaching = 2;

I am a complete noob, and using this to learn stuff. Its kinda hard to understand if it instantly gets closed.

When I do it like this: requestCommend.Body.commendation = new SteamKit2.GC.CSGO.Internal.PlayerCommendationInfo();

the program doesnt crash anymore, but cmd_friendly , cmd_teaching is set to 0;

@rossengeorgiev I never used nethook before. How can I use it for this purpose?

JustArchi commented 8 years ago

You should compile and use NetHook for reverse-engineering of functionality you're trying to implement.

I wrote short doc in my ASF, which you can use for quickstart, but I'd still suggest to compile tools youself.

(Especially because protobufs are changing constantly and they're out-of-date pretty quick)

Logxn commented 8 years ago

@JustArchi I just used it, but it doesnt seem to write anything to the function, I want to implement.

JustArchi commented 8 years ago

You're not implementing function, you're implementing functionality, that's important.

Let's say you want to make a bot that writes message in Dota 2.

You should hook nethook, then launch Dota 2 and write message, unhook, then analyze the log.

Once you have recorded communication of let's say 10 packets, you can now implement the functionality in your SK2-based project by catching appropriate EMsgs and doing exactly the same which Steam Client / Game Client would do.

For example:

PlayingGame ->
GC Hello ->
GC Response <-
GC JoinChat ->
GC Response <-
GC Chat ->

I don't know what you're trying to do, as I'm not playing CS:GO, but the general reverse-engineering is the same as adding missing Steam Client functionality, just with more complexity as you probably want to code whole functionality and not just one packet/response.

I have some examples in my ArchiHandler but they're all for adding missing SK2 functionality in Steam Client, not automating actual GC communication. However, it's pretty much the same, just more complex - with more functions and logic added. You should probably receive more help from people working with games in their SK2 projects rather than me, sorry.

Logxn commented 8 years ago

PlayingGame -> GC Hello -> GC Response <- GC CommendPlayer -> GC Respone <-

This is what it should do with my code..

JustArchi commented 8 years ago

Then it's best to record the log from SK2 client as well and compare with your original one from Steam Client to notice differences.

Logxn commented 8 years ago

@JustArchi Sorry, but thats a little to high for me. I mean I got the hello, welcome and startgame all by myself.

equestCommend.Body.commendation = new SteamKit2.GC.CSGO.Internal.PlayerCommendationInfo() { cmd_friendly = 1, cmd_leader = 4, cmd_teaching = 2 };

also this doesnt work