Jump to content

KSP Plugin debugging and profiling for Visual Studio and Monodevelop on all OS


Recommended Posts

I'm trying to make a debug installation out of a fresh installation of 1.8.1. I linked KSP_x64_Data to KSP_x64_Dbg_Data, moved WindowsPlayer.exe from windowsstandalonesupport\Variations\win64_development_mono in my Unity 2019.2.2f1 install. And renamed WindowsPlayer.exe to KSP_x64_Dbg, and edited player-connection-debug=1 into the boot.config. I'm using Windows 10.

When I launch through the debug exe, KSP launches as if it's through a normal install. The development mode label and console isn't there, and I can't attach the Unity instance to Visual Studio. Worst of all, I'm getting no error message telling me what's wrong, it's just completely silent. I don't know what to do anymore.

What's more frustrating is that the same procedure works immaculately for KSP 1.9. Am I using the wrong version of Unity? According to this and the details tab of the properties of the ksp .exe it should be correct.

I tried the simplified method by @sarbian and it let me attach through Visual Studio at least, but when I use breakpoints I get "The breakpoint will not currently be hit. Unable to find corresponding location." Debugging information is set to Portable, if that matters.

I'm going to give up and wallow in my frustration for now

EDIT: Managed to figure it out. I remembered that I also had to copy over UnityPlayer.dll and WinPixEventRuntime.dll, but it didn't work the first time. After reinstalling KSP to ensure that it was 'fresh', doing the same worked.

Edited by CrayzeeMonkey
Link to comment
Share on other sites

  • 4 weeks later...

Im trying for a 1.9.1 install and following the instructions... My unity engine is reported to be  

In output_log.txt ....  (and its on line one...)

Initialize engine version: 2017.1.3p1 (02d73f71d3bd)

But engine 2017.1.3p1  doesnt seem to exist anywhere  is eitehr location linked in OP

Unity installation (or here

There is a P4  ( Patch 2017.1.3p4 ) Sooooo... as p1 is not there.... I am going to hope P4 is just better but equiv version if the P1 that i have?

help?   maybe. 

(For future reference (other posters) if i dont come back that worked)

=============

wait up.
<misleading derp  .... elided here>

==============

double wait up

Nope I derped.

 

 

 

Edited by AxleGreaser
new info
Link to comment
Share on other sites

7 hours ago, AxleGreaser said:

Im trying for a 1.9.1 install and following the instructions... My unity engine is reported to be  

In output_log.txt ....  (and its on line one...)

Initialize engine version: 2017.1.3p1 (02d73f71d3bd

 

KSP 1.9.1 runs on Unity 2019.2.2f1. So if you are seeing 2017.1.3p1 in your logs something is definitively wrong with your install.

And I can find the 2017.1.3.p1 fine in the link mentioned in that part of the OP : "(or here if the version ends with px)". Not that it will help with your current version mismatch.

Link to comment
Share on other sites

On 6/14/2020 at 3:05 AM, sarbian said:

KSP 1.9.1 runs on Unity 2019.2.2f1. So if you are seeing 2017.1.3p1 in your logs something is definitively wrong with your install.

Ta

I now have slightly different problem then.

How and when do outputlog.txt get created.  I went back to checked i hadn't typoed || fat fingered or something and my outputlog.txt was different. :\ It now reflects the no worky state I got into 

after this step Launch KSP with the KSP_x64_Dbg.exe and check that you have "Development Build" in your lower right corner

when Id did that it said   dialogBox["Failed to load Mono"]  Now the outputlog.txt file says that too and nothing about unity.  Given my instructions hadn't mentioned installing mono yet, I decided i was a long way up a creek not too long after that. Esp when the official install mono on windows instructions that I found and followed also failed and required rebuilding it from source but.... And google suggested (by the guy who made the breaking code submission) reverting things (not even recent top of the tree ones) in the repository to fix it.  I can read not welcome here signs when they are writ that large.  (So for me, Im at not going to mono develop this month.)

My Outputlog.txt now says in its entirety...   "Unable to load mono library from F:/games/KSP1.9.1/KSP_x64_DBG_Data/MonoBleedingEdge/EmbedRuntime/mono-2.0-bdwgc.dll".

It even still says that after When I run a normal KSP install in different directory, it doesn't write outputlog.txt at all.  Should I make KSP crash or something?

(if so: then as some people do run multiple versions of KSP maybe the instructions need to point out the version number is from the most recently crashed version, or whatever it is that makes KSP actually write output log. ?)

 

Currently I just gave up on proper debugging and will compile and use log debugging. (so far that making headway, even though I compiled against the wrong unity apparently. I'm guessing the bog std calls I required for my DLL didnt change.) (edit: nope checked this out, and when I set the references in the Vi Studio project i linked against whatever was in the game install not the unity I had installed on C drive.)

Pls note (as it may be unusual): a reason i dont have monodevelop as mentioned above is I was following those steps while having no DEV environment at all. No vis C, C++, no, C#, F#, GTK, no mono, dont even currently have GCC. nuthin.

I am just getting back into development on a clean new machine. So far dont even have a linux boot.

 

On 6/14/2020 at 3:05 AM, sarbian said:

And I can find the 2017.1.3.p1 fine in the link mentioned in that part of the OP : "(or here if the version ends with px)". Not that it will help with your current version mismatch.

I now can find it too. The trick for people (if any coem after me) that don't know any French is to change the selector at the top from "tout" to your specific number as close as you get then all the patch variants p# show up for that version.

( Tout is a very versatile word in French — you'll generally find it means “all,” but you'll notice different meanings when you see all its forms. This little word can be used as an adjective, an adverb, a noun, and a pronoun, and all with varying forms. )

but in this case tout seems to have meant something like "just show me the latest of each kind of all" not actually all. I suspect the later patch variants might be considered strictly better than earlier ones (only change is fewer bugs in the inside).
Well thats what it would mean if they were my creations.

 

Self help I will be doing. Poking around more trying to find out how to get currently generated outputlog.txt to get it to tell me what my real installs of KSP recently made from installed exes claim their unity version is. (edit: see below, KSP 1.9.1 juts wont do that (write unity version to output log) anymore apparently)

I am instead moving on to printf style debugging.

Although I am having real hard think about using KOS for some of my whitebox development tool debugging. If I hack a local version of it I can expose any damn thing I like to the KOS scripts then changeup my debugging printfs without reloading the entire KSP. That should help with the annoying little bugs like what happens in this corner case (shortunsual condition of temporary duration (recent eg during actual splashdown).

============================

edit more info that Ive found

And yes it cant load it (MonoBleedingEdge/EmbedRuntime/mono-2.0-bdwgc.dll) from there as it  is not there:
  MonoBleeding Edge is beside not under the link KSP_x64_DBG_Data -> KSP_x64_Data

My Outputlog.txt now says in its entirety...   "Unable to load mono library from F:/games/KSP1.9.1/KSP_x64_DBG_Data/MonoBleedingEdge/EmbedRuntime/mono-2.0-bdwgc.dll".

and when I put soft link link in to make that work (put a MonoBleedingEdge where the code/errormsg expects it to be.)

Its (launching KSP_x64_Dbg.exe) output_log.txt now says: (in its entirety)

SOF.

mono: function mono_unity_seh_handler not found
mono: function mono_unity_set_unhandled_exception_handler not found
mono: function lookup failed

EOF

Which gets me back to wanting to get some mod coding wins using debug log style debugging. Also that will get me more up to speed on simple stuff.

me /out on proper debugging capability, for now  (I will go old skool, its fail safe and fixable by me)

yet another: Addendum

Apparently .... outputlog.txt is a pre 1.9.1 thing... BUT it still can get updated anyway when I broke it trying to debugging. (but it seems never to contain the current unity 1.9.1 version identifiers anymore.

The output log text file with the old unity version that i had (A few posts back) may have been from a carry over install I had for short time of 1.5.1/ (eventually i decided the disk data corruption) on the computer I salvaged it from was too much to bear and moved on.) hence it being olllld would have had an old unity install version number.

 

On 6/14/2020 at 9:15 AM, RyanRising said:

Same folder, but it’s called Player.log instead of output_log.txt. On Windows, they changed that in 1.8, so the last version that would give an output_log.txt was 1.7.3. See here 

Looking around in my much larger player Log (that1.9.1 creates), I have not yet found the unity build number identified in the same way.

 

 

Edited by AxleGreaser
Link to comment
Share on other sites

  • 2 weeks later...

G'day, just as a heads-up if anybody else is scratching their heads about this, you need a later Unity version (I just tried 2019.2.2f1 and it worked) if you want to profile your mods.

The profiler in 2017.1.3p1 doesn't connect/work with the current version of KSP, despite it being the "correct" version of Unity.

Link to comment
Share on other sites

  • 1 month later...
On 3/31/2020 at 7:41 PM, sarbian said:

New simplified method! Only 1 file to copy.

....

I ll update the OP after other have confirmed it work for them

Few months later... I can confirm too, that it's working (KSP 1.9.1, Visual Studio 2017)

Link to comment
Share on other sites

  • 1 month later...
On 11/12/2019 at 8:48 AM, Papa_Joe said:

for those that would like, I have created a batch script that automates the update and distribution of a new game to my development environment.  It makes the process very painless.

The batch script is menu driven, so you can perform all actions, or only one at a time.  Also it pauses between steps, so you can see what is going on.  This script is specific to my environment, but it uses txt files for folder locations, so you should be able to adapt it for your needs and your environment.

 

@echo off
rem  This file sets up a fresh Development mode install of KSP from a Steam installation
rem  This script assumes that an existing development copy exist somewhere on your system besides steam.
rem  The script uses text files containing locations of various components needed for the script to work.

rem  Change Log:
rem  v2.0  add support for unity 2019.
cd %~dp0
set LCL_DIR=%~dp0

set VERSION=""
set space = " "

set /p GIT_DIR=<"%LCL_DIR%\git_dir.txt"
set /p STEAM_DIR=<"%GIT_DIR%\_LocalDev\steam_dir.txt"
set /p KSP_DIR=<"%GIT_DIR%\_LocalDev\ksp_dir.txt"

@echo: 
@echo     Path tokens:
@echo     - LCL_DIR: %LCL_DIR%
@echo     - STEAM_DIR: %STEAM_DIR%    
@echo     - GIT_DIR: %GIT_DIR%
@echo     - KSP_DIR: %KSP_DIR%
@echo:
@echo   Let's get the version of the existing game...

rem get_versions
set steamVer = ""
for /F "usebackq skip=13 delims=" %%V in ("%STEAM_DIR%\readme.txt") do set "steamVer=%%V" & goto Steamvalue

:Steamvalue
set thisVer = ""
for /F "usebackq skip=13 delims=" %%V in ("%KSP_DIR%\readme.txt") do set "thisVer=%%V" & goto Hasvalue

:Hasvalue
call set VERSION=%%thisVer:Version =%word%%%

@echo     - Steam Version found is:  %steamVer%
@echo     - Dev Version found is: %thisVer%
set /p quit= "  - Do you wish to continue? (Y/N):  "
if /i "%quit%" == "N" ( 
	@echo     - Terminating batch operation without executing Dev Setup...
	goto end 
)

:menu
@echo:
@echo:
@echo     ====================================================
@echo     Main Menu:
@echo:
@echo     1 - Perform all steps...
@echo     2 - Backup existing game folder...
@echo     3 - Remove existing game folder...
@echo     4 - Create new game folder...
@echo     5 - Copy Steam game folder...
@echo     6 - Copy new KSP assemblies to Dev...
@echo     7 - Copy Dev Debug files to Game folder...
@echo     8 - Copy Game Save and Ships to Game folder...
@echo     9 - Create linked folder...
@echo     X - Quit script  (Do nothing!)
@echo     ====================================================
@echo:
set /p optn= "---> Select option (1 - 9, X):  "
@echo:
@echo     Choice made:  "%optn%"
@echo:

if "%optn%" == "1" ( goto backupGame )
if "%optn%" == "2" ( goto backupGame )
if "%optn%" == "3" ( goto removeGame )
if "%optn%" == "4" ( goto createFolder )
if "%optn%" == "5" ( goto copyGame )
if "%optn%" == "6" ( goto copyAssemblies )
if "%optn%" == "7" ( goto copyDebugFiles )
if "%optn%" == "8" ( goto copyGameSaves )
if "%optn%" == "9" ( goto createLinkedFolder )
if /I "%optn%" == "X" ( goto end )

goto end

:backupGame
@echo: 
@echo     - Backup existing game folder...

@echo: 
pause
@echo: 

@echo     - Backup in progress, please wait...
xcopy /E /Y /Q "%KSP_DIR%\*.*" "%KSP_DIR%_%VERSION%_old\"

@echo     - Backup complete...
@echo: 

if not "%optn%" == "1" ( goto end )

:removeGame
@echo     - Removing existing game folder...
pause
rmdir /s /q "%KSP_DIR%"
@echo     - Removal complete...
@echo: 
if not "%optn%" == "1" ( goto end )

:createFolder
@echo     - Creating new game folder...
pause
if not exist "%KSP_DIR%" ( 
	mkdir "%KSP_DIR%" 
	@echo     - Game folder created...
) else (
	@echo     - Game folder exists.  Skipping...
)
@echo:
if not "%optn%" == "1" ( goto end )

:copyGame
@echo     - Ready to Copy Steam Game to local Game folder...
@echo       from: "%STEAM_DIR%" 
@echo         to: "%KSP_DIR%"
pause
xcopy /E /Y "%STEAM_DIR%\*.*" "%KSP_DIR%\"
@echo     - Copy complete...
@echo:
if not "%optn%" == "1" ( goto end )

:copyAssemblies
@echo     - Ready to Copy KSP and unity assemblies 
@echo       from: "%KSP_DIR%\KSP_x64_Data\Managed" 
@echo         to: "%GIT_DIR%\_LocalDev\KSPRefs\" folder...
pause
xcopy /E /Y "%KSP_DIR%\KSP_x64_Data\Managed\Assembly-CSharp.dll" "%GIT_DIR%\_LocalDev\KSPRefs\"
xcopy /E /Y "%KSP_DIR%\KSP_x64_Data\Managed\Assembly-CSharp-firstpass.dll" "%GIT_DIR%\_LocalDev\KSPRefs\"
xcopy /E /Y "%KSP_DIR%\KSP_x64_Data\Managed\KSPAssets.dll" "%GIT_DIR%\_LocalDev\KSPRefs\"
xcopy /E /Y "%KSP_DIR%\KSP_x64_Data\Managed\UnityEngine.dll" "%GIT_DIR%\_LocalDev\KSPRefs\"
xcopy /E /Y "%KSP_DIR%\KSP_x64_Data\Managed\UnityEngine.*.dll" "%GIT_DIR%\_LocalDev\KSPRefs\"
xcopy /Y "%KSP_DIR%\readme.txt" "%GIT_DIR%\_LocalDev\KSPRefs\"
@echo     - Copy complete...
@echo:
if not "%optn%" == "1" ( goto end )

:copyDebugFiles
@echo     - Ready to Copy unity debug files to game folder and set debug mode...
pause
@echo player-connection-debug=1 >> "%KSP_DIR%\KSP_x64_Data\boot.config
copy /Y "%LCL_DIR%\WindowsPlayer.exe" "%KSP_DIR%\ksp_x64_dbg.exe"
copy /Y "%LCL_DIR%\UnityPlayer.dll" "%KSP_DIR%"
copy /Y "%LCL_DIR%\WinPixEventRuntime.dll" "%KSP_DIR%"
@echo     - Copy complete...
@echo: 
if not "%optn%" == "1" ( goto end )

:copyGameSaves
@echo     - Ready to Copy ships, Saves and mods to the new game folder.
pause
xcopy /E /Y /D "%KSP_DIR%_%VERSION%_old\GameData\*.*" "%KSP_DIR%\GameData\"
xcopy /E /Y /D "%KSP_DIR%_%VERSION%_old\ships\*.*" "%KSP_DIR%\Ships\"
xcopy /E /Y /D "%KSP_DIR%_%VERSION%_old\saves\*.*" "%KSP_DIR%\saves\"
@echo     - Copy complete...
@echo: 
if not "%optn%" == "1" ( goto end )

:createLinkedFolder
@echo     - Ready to create the linked folder for debugging...
@echo: 
pause

REM cd /d "%KSP_DIR%"
REM @echo     - Curr Dir:  "%cd%"
REM @echo     - Game Directory:  "%KSP_DIR%"...
REM @echo: 
REM pause

mklink /J "%KSP_DIR%"\KSP_x64_Dbg_Data "%KSP_DIR%"\KSP_x64_Data
@echo     - Linked folder created...
@echo:

:end
cd %~dp0
@echo     - %~dp0
@echo:
@echo     - script complete...
@echo:
pause

The script performs the following actions:

 

1.  checks to see if a new version of the game exists in Steam, compared to the latest copy of your development version of the game.  It checks the readme.txt to get the version information.

2.  Backs up the existing dev game folder for archival needs.

3.  deletes the existing dev game folder

4.  Copies all files from the steam installation into a new game folder.

5.  copies all the KSP and unity assemblies needed for development into a location of your choice.  I do this to ensure I have the latest assemblies, and they are not tied to my steam installation.  Keeps them in sync.  Makes multi developer easier, as the assemblies are in a common location for all KSP mods I supported.

6.  Copies the debug files ( WIndowsPLayer.exe, UnityPlayer.dll and WinPixEventRuntime.dll into the dev game root folder  It also sets the flag in Boot.config.

7  Copies any existing saves, ships, and mods from the previous dev game installation over to the new Dev Game installation.

8.  Creates the linked Folder, and finally  lets you know it is done.

I hope this is helpful.  The paths in the .txt files are one line only.  This is assumed by the command reading from the file.  It will only retrieve the first line.  You could add all paths to a single file if you wish and simply read each line and assign to your vars using a different file handling technique.

 

If you have any questions, let me know.  This script has been tested, and I use it regularly.  It should work both by executing the script as a .bat, or by running it in power shell.

Hi, I've been trying to debug a simple test mod with this method on KSP latest version.

I'm running the batch without errors with Unity 2019.2.2f1. Running ksp_x64_dbg.exe shows "development build" on bottom right. I can Attach Unity Debugger from Visual Studio 2019 and everything looks fine. The issue is that breakpoints cannot be hit.

Opening Debug > Windows > Modules on Visual Studio shows that no symbols are being loaded for any assembly, which seems the main issue.

I'm compiling the mod as a C# library targeting .NET Framework 4 and I've tried changing the Debugging information to Portable, as Gotmachine mentions, but no luck.

Also tried using the 1 file method from Sarbian in this same thread, but no luck either.

Any suggestions?

Link to comment
Share on other sites

9 hours ago, metalbass_92 said:

Hi, I've been trying to debug a simple test mod with this method on KSP latest version.

I'm running the batch without errors with Unity 2019.2.2f1. Running ksp_x64_dbg.exe shows "development build" on bottom right. I can Attach Unity Debugger from Visual Studio 2019 and everything looks fine. The issue is that breakpoints cannot be hit.

Opening Debug > Windows > Modules on Visual Studio shows that no symbols are being loaded for any assembly, which seems the main issue.

I'm compiling the mod as a C# library targeting .NET Framework 4 and I've tried changing the Debugging information to Portable, as Gotmachine mentions, but no luck.

Also tried using the 1 file method from Sarbian in this same thread, but no luck either.

Any suggestions?

What works for me with VS 2019:

  • My project build as Debug and mod's pdb file copied along with dll into test version of KSP
  • Dll from Sarbian
  • Unity debugger attached to the port 55555
  • Then I start ksp_x64.exe and as soon as the main menu (and my mod) is loaded, the breakpoints are registered
Link to comment
Share on other sites

4 hours ago, maja said:

as soon as the main menu (and my mod) is loaded, the breakpoints are registered

This was it! My tests consisted on waiting until the menu was open, but I was using [KSPAddon(KSPAddon.Startup.SpaceCentre, true)] to load it.

So it was actually working, but I checked before my dll was loaded.

Thank you :)

Edited by metalbass_92
Added additional explanation of what was wrong
Link to comment
Share on other sites

  • 3 weeks later...
On 4/23/2020 at 6:09 PM, LucidDan said:

 

I used this to great success in 1.9.1 as well, thanks @whitespacekilla!

 

I tried following this and successfully got KSP to run as a "development build", but whenever I try to connect to it from Rider from the running process list, I get 

Failed to connect: Connection refused 127.0.0.1:56402
Unable to connect to UnityPlayer

Did you run into this? any idea what I'm doing wrong? Rider is version 2020.1.4 so maybe something changed recently?

Link to comment
Share on other sites

On 10/7/2020 at 12:06 AM, m4v said:

did you add "player-connection-debug=1" in KSP_Data/boot.config?

I thought I did, turns out I put it in "boon.config" :huh:

now I'm getting the same error but the KSP runtime is printing `debugger-agent: Unable to listen on 8` to the console, I guess time to figure out what thats about

Edited by cineboxandrew
Link to comment
Share on other sites

  • 2 months later...
  • 3 weeks later...

@sarbian

Getting the following error when trying to use the mono-2.0-bdwgc.dll:

* Assertion at D:\Sarbian\Documents\GitHub\dnSpy-Unity-mono\unity-2019.2.2-mbe\mono\metadata\mono-debug.c:137, condition `!mono_debug_initialized' not met

Only other changes are:

Following three files come from the Unity instal to the main KSP directoryl:

"<UNITY>/Hub/Editor/2019.2.2f1/Editor/Data/PlaybackEngines/windowsstandalonesupport/Variations/win64_development_mono"

  • Replace the normal ksp_x64.exe with the WindowsPlayer.exe, named to ksp_x64_dbg.exe
  • Replaced the UnityPlayer.dll with the one in the same directory
  • Copied over WinPixEventRuntime.dll

and

  • Replaced the mono-2.0-bdwgc.dll with  yours


If I don't do the bdwgc replacement, it doesn't error.  Strangely enough, using the normal bdwgc, I am able to attach to the unity debugger and breakpoints do seem to be working

 

 

Link to comment
Share on other sites

  • 3 months later...
On 3/29/2015 at 1:09 PM, sarbian said:

Once you have that you will have a "Attach Unity Debugger" in the Debug menu.

This part tripped me up for an hour or so. Wouldn't work in Visual Studio no matter what I did. Even when trying to edit code from within Unity. Then I repaired my VS  (2019 Community) installation, which nuked the VisualAssist and UE4 plugins but in exchange I finally got the Unity debugger option. Looks like one of those doesn't play nice with the Unity Tools plugin.

I also got the warning from VS mentioned above, about how "this breakpoint won't be triggered" yada yada, but they actually triggered just fine (maybe VS gets confused because it's inside a dynamically loaded mod or w/e). 

Thanks for the detailed instructions, sarbian et al. 

Link to comment
Share on other sites

  • 1 month later...

Some notes for debugging for KSP 1.12 in Linux:

KSP now uses Unity 2019.4.18f1, you need to download that, see here for instructions

Everything is the same except copying the LinuxPlayer file part, the file you need to copy now is UnityPlayer.so, overwriting the one in your KSP install.

Edited by m4v
Link to comment
Share on other sites

14 hours ago, m4v said:

Everything is the same except copying the LinuxPlayer file part, the file you need to copy now is UnityPlayer.so, overwriting the one in your KSP install.

This isn't working for me (on Ubuntu 20.04.2). I'm getting

Could not load symbol mono_unity_class_is_open_constructed_type : (null)
 
(Filename: ./Runtime/Modules/LoadDylib.cpp Line: 199)

mono: function mono_unity_class_is_open_constructed_type not found
Could not load symbol mono_unity_managed_callstack : (null)
 
(Filename: ./Runtime/Modules/LoadDylib.cpp Line: 199)

mono: function mono_unity_managed_callstack not found
mono: function lookup failed
Failed to load mono

in my ~/.config/unity3d/Squad/Kerbal Space Program/Player.log file. It was working prior to 1.12. Any thoughts?

Link to comment
Share on other sites

@DocNappersI have no idea, and I'm in Ubuntu 20.04.2 too. The only difference I have with severedsolo's procedure that I can think of is that I compile with mono's msc  thus the debugging symbols are in .mdb files.

Edited by m4v
Link to comment
Share on other sites

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.

 Share

×
×
  • Create New...