Jump to content

Hooking into memory handles


Recommended Posts

Wasn\'t entirely sure where to put this, as it\'s not for an addon or plugin for KSP itself, but for a companion program for something else...

What I\'m looking to do is use a program to hook a game .dll and read various variables, such as attitude, altitude, orbit details, velocity, etc in realtime (or with at most a half-sec delay). Is there a .dll I can hook into to grab this information, or would I need a plugin to expose the data? Does MechJeb do that already...?

Link to comment
Share on other sites

Most programs that do this just open up a listen socket and transfer info over TCP or UDP to client apps. In this case, you\'d write a plugin that acts as a server, which your app just hooks into.

Link to comment
Share on other sites

I may as well be explicit... I\'m looking at creating a plugin for LCDStudio to put flight-data on my Logitech G13\'s screen (and let other people put flight data on any LCD that LCDStudio supports).

I\'m not much of a coder, and I\'ve only made one plugin for LCDStudio previously (puts data from X³:TC onto the LCD, but this works by having an in-game script send the data to a log-file, and the plugin reads that). The reason I asked about hooking into the DLLs is that this seems to be the main way that LCDStudio plugins work (such as the RivaTuner one that\'ll post system temperature data). I\'ve no idea if that\'s done by TCP/UDP or what, really...

Any advice or help appreciated. If this is moving towards an in-game plugin tho, I may as well ask for this thread to be moved.... can you?

(Wouldn\'t a good solution all-round be a plugin that sends out all this data to anything that listens, so anyone can build on that plugin with external apps...?)

Link to comment
Share on other sites

(I could of sworn I posted... maybe I hit preview and closed it? It is late...)

Ok, found loads of stuff in Assembly-CSharp.dll through the object browser (only looking for public ones). Don\'t seem to be able to get to any of it, though. What\'s wrong with this?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using UnityEngine;



namespace KSPexplore
{
public partial class Form1 : Form
{
public Form1()
{

InitializeComponent();
textBox1.Text = Convert.ToString(Vessel.vesselName);


}
}
}

It SHOULD put the vessel\'s name in the form\'s textbox, right...? Instead it tells me:

Error 1 An object reference is required for the non-static field, method, or property \'Vessel.vesselName\'

And yes, I\'ve added references to the Assembly-CSharp and UnityEngine dlls.

Link to comment
Share on other sites

(I could of sworn I posted... maybe I hit preview and closed it? It is late...)

Ok, found loads of stuff in Assembly-CSharp.dll through the object browser (only looking for public ones). Don\'t seem to be able to get to any of it, though. What\'s wrong with this?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using UnityEngine;



namespace KSPexplore
{
public partial class Form1 : Form
{
public Form1()
{

InitializeComponent();
textBox1.Text = Convert.ToString(Vessel.vesselName);


}
}
}

It SHOULD put the vessel\'s name in the form\'s textbox, right...? Instead it tells me:And yes, I\'ve added references to the Assembly-CSharp and UnityEngine dlls.

You\'re calling a non-static variable as though it were static. Also you\'re trying to use Winforms, which isn\'t available.
Link to comment
Share on other sites

Actually it\'s a form program - I\'m trying to confirm the data\'s availability before I write the .dll for LCDStudio.

It\'s the 'You\'re calling a non-static variable as though it were static. ' bit that has me stumped. How do I correct that?

Link to comment
Share on other sites

I used to get this error all the time in my java intro class last year. Sadly I forgot how to fix it. Or maybe I do know, but have no idea what I\'m actually doing.

Pulling everything I can, and trying not to sound like a monkey with a dunce hat on...

I believe you have to store Vessel.vesselName to a variable before using it.

so like, vesName = Vessel.vesselName;

I would think you would want \'()\' after \'vesselName\' though.

I believe this is because it\'s a static variable

But yeah...been a solid year since I\'ve done any programming...and it was super basic at that

Something tells me I might have things reversed, getting a static -> non-static

Welp, I was wrong

This looks right though.

http://stackoverflow.com/questions/2042813/calling-non-static-method-in-static-method-in-java

Link to comment
Share on other sites

Cheers - I tried that, and couldn\'t get it to work (the code seemed ok, but getting the data into the form eluded me). Either I\'m missing something fundamental (likely. It\'s been many years (pre-C) since I did any coding) or what I\'m trying to do isn\'t possible.

If anyone can show an example of it working, I would be eternally grateful - just getting the current ship name from into the textbox without using a KSP plugin would be enough for me to do what I need to.

Link to comment
Share on other sites

Cheers - I tried that, and couldn\'t get it to work (the code seemed ok, but getting the data into the form eluded me). Either I\'m missing something fundamental (likely. It\'s been many years (pre-C) since I did any coding) or what I\'m trying to do isn\'t possible.

If anyone can show an example of it working, I would be eternally grateful - just getting the current ship name from into the textbox without using a KSP plugin would be enough for me to do what I need to.

Your problem appears to be trying to access [tt]Vessel[/tt], which is actually an object, instead of using [tt]vessel[/tt], which would be the instance of the object.

Try this instead:

textBox1.Text = vessel.vesselName; // it\'s already a string, so no need to convert anything

You have to figure out the GUI part yourself, can\'t help you with that :/

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...