Have openMW launch through steam

Not about OpenMW? Just about Morrowind in general? Have some random babble? Kindly direct it here.
Post Reply
Pholux
Posts: 6
Joined: 09 Jun 2016, 00:47

Have openMW launch through steam

Post by Pholux » 09 Jun 2016, 00:51

Aside from launching openMW in steam through "add non-steam game", is it possible to launch through the morrowind appid itself so it tracks playtime along with screenshots?

SquireNed
Posts: 397
Joined: 21 Dec 2013, 22:18

Re: Have openMW launch through steam

Post by SquireNed » 09 Jun 2016, 02:27

Probably not. You could copy-paste the OpenMW executable into your standard Morrowind folder and have it replace whatever Steam launches when you launch the game and see if it works, but I don't know if that will work.

User avatar
scrawl
Posts: 2103
Joined: 18 Feb 2012, 11:51
Contact:

Re: Have openMW launch through steam

Post by scrawl » 09 Jun 2016, 02:43

There is a way to make Steam think that a particular game is running without actually running that game... idle-master does it. All you need to do is initialize the Steam API with the correct appId. I'd imagine that screenshots would work as well if the Steam overlay calls the Steam API to find out which game is running.

So... pretty much, you need to inject a DLL that starts up the Steam API. Shouldn't be too difficult to make.

User avatar
scrawl
Posts: 2103
Joined: 18 Feb 2012, 11:51
Contact:

Re: Have openMW launch through steam

Post by scrawl » 09 Jun 2016, 03:07

Just a quick test... it works:

Image

Here's how I did it - I just added code to OpenMW that initializes the steam API. Ideally this code should be in a DLL so that it can be used for any other game not just OpenMW.

Code: Select all

diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt
index 8e938e0..a1dee30 100644
--- a/apps/openmw/CMakeLists.txt
+++ b/apps/openmw/CMakeLists.txt
@@ -119,6 +119,7 @@ include_directories(
 )
 
 target_link_libraries(openmw
+    "dl"
     ${OSG_LIBRARIES}
     ${OPENTHREADS_LIBRARIES}
     ${OSGPARTICLE_LIBRARIES}
diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp
index a4bf1fe..c730168 100644
--- a/apps/openmw/main.cpp
+++ b/apps/openmw/main.cpp
@@ -13,6 +13,8 @@
 #include <boost/iostreams/stream_buffer.hpp>
 #include <boost/filesystem/fstream.hpp>
 
+#include <dlfcn.h>
+
 #if defined(_WIN32)
 // For OutputDebugString
 #ifndef WIN32_LEAN_AND_MEAN
@@ -294,6 +296,17 @@ private:
 
 int main(int argc, char**argv)
 {
+    setenv("SteamAppId", "22320", 0);
+
+    void* steamapi = dlopen("./libsteam_api64.so", RTLD_LAZY);
+    if (!steamapi)
+        throw std::runtime_error("Can't open libsteam_api64.so");
+    typedef void funcsig(void);
+    funcsig* steamapi_init = (funcsig*) dlsym(steamapi, "SteamAPI_Init");
+    if (steamapi_init == NULL)
+        throw std::runtime_error("Can't find SteamAPI_Init");
+    steamapi_init();
+
 #if defined(__APPLE__)
     setenv("OSG_GL_TEXTURE_STORAGE", "OFF", 0);
 #endif
Then all that's left is to launch OpenMW with the steam overlay loaded:

Code: Select all

LD_PRELOAD=/home/scrawl/Steam/ubuntu12_64/gameoverlayrenderer.so ./openmw

Pholux
Posts: 6
Joined: 09 Jun 2016, 00:47

Re: Have openMW launch through steam

Post by Pholux » 09 Jun 2016, 15:12

scrawl wrote:Just a quick test... it works:

Image

Here's how I did it - I just added code to OpenMW that initializes the steam API. Ideally this code should be in a DLL so that it can be used for any other game not just OpenMW.

Code: Select all

diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt
index 8e938e0..a1dee30 100644
--- a/apps/openmw/CMakeLists.txt
+++ b/apps/openmw/CMakeLists.txt
@@ -119,6 +119,7 @@ include_directories(
 )
 
 target_link_libraries(openmw
+    "dl"
     ${OSG_LIBRARIES}
     ${OPENTHREADS_LIBRARIES}
     ${OSGPARTICLE_LIBRARIES}
diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp
index a4bf1fe..c730168 100644
--- a/apps/openmw/main.cpp
+++ b/apps/openmw/main.cpp
@@ -13,6 +13,8 @@
 #include <boost/iostreams/stream_buffer.hpp>
 #include <boost/filesystem/fstream.hpp>
 
+#include <dlfcn.h>
+
 #if defined(_WIN32)
 // For OutputDebugString
 #ifndef WIN32_LEAN_AND_MEAN
@@ -294,6 +296,17 @@ private:
 
 int main(int argc, char**argv)
 {
+    setenv("SteamAppId", "22320", 0);
+
+    void* steamapi = dlopen("./libsteam_api64.so", RTLD_LAZY);
+    if (!steamapi)
+        throw std::runtime_error("Can't open libsteam_api64.so");
+    typedef void funcsig(void);
+    funcsig* steamapi_init = (funcsig*) dlsym(steamapi, "SteamAPI_Init");
+    if (steamapi_init == NULL)
+        throw std::runtime_error("Can't find SteamAPI_Init");
+    steamapi_init();
+
 #if defined(__APPLE__)
     setenv("OSG_GL_TEXTURE_STORAGE", "OFF", 0);
 #endif
Then all that's left is to launch OpenMW with the steam overlay loaded:

Code: Select all

LD_PRELOAD=/home/scrawl/Steam/ubuntu12_64/gameoverlayrenderer.so ./openmw
Would I just need to copy that code and paste it into notepad or notepad++? I'm just a little concerned because whenever I hear of DLL injecting I think of cheating but Morrowind doesn't have VAC protection so I think I should be fine. It also looks like you're running on linux so what changes would I have to make for it to work on windows?

Pholux
Posts: 6
Joined: 09 Jun 2016, 00:47

Re: Have openMW launch through steam

Post by Pholux » 09 Jun 2016, 19:50

Bumping this since I don't understand how to inject dll files.

User avatar
scrawl
Posts: 2103
Joined: 18 Feb 2012, 11:51
Contact:

Re: Have openMW launch through steam

Post by scrawl » 09 Jun 2016, 21:06

That is not something you can do as an end user, you'll need to wait for someone (a programmer) to compile a tool that does it for you. This tool will have to be built for the particular operating system that you are using. I do not use windows so I can't do it for you.

There is also the issue of trust, you don't want to be running a random person's DLL file, there could be a virus in it. I could think of a simpler version that works with just a Python script, that would work for tracking playtime but wouldn't work for taking screenshots and having those saved as Morrowind screenshots in Steam.. because the Steam API would be started outside of the OpenMW process, the steam overlay would not be able to know that it is running Morrowind.

Pholux
Posts: 6
Joined: 09 Jun 2016, 00:47

Re: Have openMW launch through steam

Post by Pholux » 10 Jun 2016, 00:02

scrawl wrote:That is not something you can do as an end user, you'll need to wait for someone (a programmer) to compile a tool that does it for you. This tool will have to be built for the particular operating system that you are using. I do not use windows so I can't do it for you.

There is also the issue of trust, you don't want to be running a random person's DLL file, there could be a virus in it. I could think of a simpler version that works with just a Python script, that would work for tracking playtime but wouldn't work for taking screenshots and having those saved as Morrowind screenshots in Steam.. because the Steam API would be started outside of the OpenMW process, the steam overlay would not be able to know that it is running Morrowind.
Maybe that could be a suggestion for future releases of openmw, but of course more things are important. Maybe someone will volunteer to make it as well.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest