Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SteamInput GetDigitalActionGlyph returns a null string. #708

Closed
ramunator opened this issue Feb 28, 2023 · 10 comments
Closed

SteamInput GetDigitalActionGlyph returns a null string. #708

ramunator opened this issue Feb 28, 2023 · 10 comments
Assignees

Comments

@ramunator
Copy link

Describe the bug
GetDigitalActionGlyph returns a null string instead of the path to the icon.

To Reproduce
Steps to reproduce the behaviour: paste the code into your project maybe assign the keyboard icon if wanted

Calling Code

public static Texture2D LoadSteamGlyph(string digitalActionHandle, Texture2D keyboardIcon = null)
    {
        if (!SteamClient.IsLoggedOn)
        {
            Console.Log("Can't get icon while steam client is not running " + digitalActionHandle);
            return null;
        }

        SteamInput.RunFrame();

        if (SteamInput.Controllers.Count() != 0)
        {
            var controller = SteamInput.Controllers.ElementAt(0);
            
            Console.Log("Get icon for controller " + controller.Id + " path " + digitalActionHandle);
            
            string localGlyphPath = SteamInput.GetDigitalActionGlyph(controller, digitalActionHandle);

            if (string.IsNullOrEmpty(localGlyphPath))
            {
                Console.Log("Could not get icon of controller");
                return null;
            }

            Console.Log("Got icon of controller " + localGlyphPath);
            
            Texture2D iconTexture = LoadImage(localGlyphPath);
            return iconTexture;
        }
        else
        {
            Console.Log("No controller connected");
        }

        return keyboardIcon;
    }

Expected behaviour
I expect the function to return a Texture2D of the glyph relative to the handle

Desktop (please complete the following information):

  • OS: PC
  • Unity: [e.g Unity 2019.3.18f]

Additional context
Hey, so this code should return the icon right? Nothing is returned. The controller id gets shown in the console. the localGlyphPath returns null for some reason. Please help I have no idea why this is happening. Also, the digitalActionHandle is correct and reading input works fine

@Peewi
Copy link

Peewi commented Mar 2, 2023

I'm surprised to hear that reading input is working. I found that it wasn't working because Steam Input never got initialized.

I only got it to work after making a fork that calls the internal Init method, but with that change GetDigitalActionGlyph works and returns a path to an image file.

@ramunator
Copy link
Author

Yes indeed i Also had to decompile the dll add the Internal.init func but it does only make the controller detection work. What exactly have you changed and how do you get the icon

@Peewi
Copy link

Peewi commented Mar 3, 2023

In SteamInput.InitializeInterface I added a call to Internal.Init( false ). I have made no other changes to existing methods.

You say you decompiled the DLL. If you mean the DLL from the most recent release, it is 3 years old and there have been many code changes since then. It might make a difference if you build from the current source instead.

@ramunator
Copy link
Author

ramunator commented Mar 3, 2023

Thanks for the answer. I used dotPeek to decompile some stuff had to be changed to get bo errors not sure if i removed some stuff Also i Think i set the init to false. Are you using dll files for your project or what are you doing? / should i just download the source from GitHub?

@Peewi
Copy link

Peewi commented Mar 4, 2023

I am still using Facepunch.Steamworks in the form of a DLL. Just one I compiled, instead of an out-of-date release.

When doing this, remember to also use the latest Steamworks DLL (version 1.55).

@ramunator
Copy link
Author

seem to get an error called something like "'Facepunch.Steamworks.Win64' with identity 'Facepunch... uses 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' which has a higher version than referenced assembly 'System.Runtime' with identity 'System.Runtime, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'"

i don't know how to make system.runtime at version 6

@ramunator
Copy link
Author

ramunator commented Mar 7, 2023

Thanks for all t he help
After a while i figured it out.

  1. Download the source code and not the release.
  2. Go into the folder and open the file "Facepunch.Steamworks.Win64.csproj" in visual studio.
  3. Right-click on the solution and hit build solution.
  4. Drag the generated files from "Folder/Facepunch.Steamworks\bin\Debug\net46"
    make sure it's 4.6 and not 6.0, I just dragged the win64 files in because it gives errors when dragging more DLL's
  5. Go into unity and create a script something like this one

`
public RawImage icon;

private string cached = string.Empty;

IEnumerator LoadTextureFromCache(string filePath)
{
    if (!File.Exists(filePath))
    {
        yield break;
    }
    var www = UnityWebRequestTexture.GetTexture("file://" + filePath);
    yield return www.SendWebRequest();
    //texture loaded
    icon.texture = DownloadHandlerTexture.GetContent(www);

}

private void Update()
{
    if (!string.IsNullOrEmpty(cached))
    {
        return;
    }
    Controller controller = SteamInput.Controllers.ElementAt(0);
    controller.ActionSet = "Action Set";
    cached = SteamInput.GetPngActionGlyph(controller, "Handle", GlyphSize.Small);

    if (string.IsNullOrEmpty(cached))
    {
        return;
        
    }
    
    Console.Log("Found controller icon, path: " + cached);
    StartCoroutine(LoadTextureFromCache(cached));
}`

@stoora
Copy link

stoora commented May 13, 2023

Hi I'm trying to detect joycon pair controllers. I edited and recompiled and referenced the dll correctly but controller collection always empty.
How did you manage to detect controllers correctly?

SteamClient.Init(1456390);
SteamInput.Controllers.Count(); 👈 always 0

@ramunator
Copy link
Author

well if they detect in steam and show up as connected in the steam client they should pop up after using init. You could try and log the steaminput.controllers count in update

@stoora
Copy link

stoora commented May 13, 2023

Actually yes..., I'm double checking in the update method.
I've just got it to work with a little hack.
I had to force 'openInterface' by bypassing the 'valid' check in "SteamClient.cs". and recompiled the assembly.

internal static void AddInterface<T>() where T : SteamClass, new() { var t = new T(); bool valid = t.InitializeInterface( false ); openInterfaces.Add( t ); //if ( valid ) //{ // openInterfaces.Add( t ); //} //else //{ // t.DestroyInterface( false ); //} }

this may not be the correct way to do it but it's my only solution for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants