Skip to content

Download PDB using PInvoke#9

Merged
xiaoxiao921 merged 8 commits into
xiaoxiao921:masterfrom
DaXcess:pinvoke-download
Oct 5, 2025
Merged

Download PDB using PInvoke#9
xiaoxiao921 merged 8 commits into
xiaoxiao921:masterfrom
DaXcess:pinvoke-download

Conversation

@DaXcess

@DaXcess DaXcess commented May 14, 2025

Copy link
Copy Markdown
Contributor

For a while Unity has been enforcing HTTPS on their symbol servers, which is a problem because during the patcher phase in BepInEx, HTTPS is not yet supported.

This was initially fixed by shipping an external executable which would download the PDB file. This is however an undesirable solution for a couple of reasons:

  • Having to ship an extra executable increases complexity
  • Thunderstore's automated filters don't really like Process.Start and ProcessStartInfo
  • This technique only supports Windows (and probably Wine/Proton, but not Linux or MacOS native games)

A more elegant solution is to use PInvoke to use native system libraries to perform the download for us.

Windows

On Windows, we can leverage the winhttp.dll library to download the PDB files. winhttp.dll is used by BepInEx as the chainloader proxy anyways, so it's basically guaranteed to exist.

This project only seems to support Windows anyways, so Linux/MacOS support can be ignored

Testing

  • Windows
  • Linux (Wine/Proton)

@DaXcess

DaXcess commented May 14, 2025

Copy link
Copy Markdown
Contributor Author

image

PInvoke download works on Windows (had to replace wininet with winhttp because wininet was throwing PROC_NOT_FOUND errors). Since winhttp also is included with Wine/Proton this means that this also works in those contexts.

@DaXcess DaXcess marked this pull request as ready for review May 14, 2025 18:40
Additionally, made the generic download method only be able to download from the Unity symbol server
@xiaoxiao921

Copy link
Copy Markdown
Owner

Sorry for not backing to you before but i didn't merge and ignored this pr because to my mind there was just no specific reasons to merge as it was just a refactor of effectively an already working solution with no pros as i don't think the extra exe in a zip that is installed automatically by mod managers would change anything and that the TS filter was gonna trigger regardless due to the amount of native stuff this project is interacting with + your solution is using pinvokes which also trigger the filter anyway.

But i'm fine with moving ahead with this solution since you also support pd_ and pdb files. I'm also fine if you wanna solve #12 on this pr too i'll be happy to merge it

@DaXcess

DaXcess commented Oct 5, 2025

Copy link
Copy Markdown
Contributor Author

Okay, for #12 merged my 2022.3.62 branch into this PR.

The best thing I could come up with was adding a new property to UseRightStructs called IsFileCreatedRelative, which is currently only set whenever the Unity version is 2022.3.62 or higher, but flipped back to false if it's 2023+.

Then in the IsFileCreated hook I check if it's relative, and if so use RelativePathString instead of AbsolutePathString to read the path (which uses the already existing GetStruct<T> that already supports abstraction). Let me know if you think there's better ways to achieve this, otherwise I think this should be good.

Comment thread src/FixPluginTypesSerialization/Patchers/IsFileCreated.cs Outdated
This was linked to issues Oct 5, 2025
@xiaoxiao921 xiaoxiao921 merged commit cee1387 into xiaoxiao921:master Oct 5, 2025

namespace FixPluginTypesSerialization.UnityPlayer.Structs.v5.v0
{
public class IsFileCreatedParam : IIsFileCreatedParam

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't have an ApplicableToUnityVersionsSince so any version below 2022.3.62 will fail, you also don't have another IsFileCreatedParam for versions startig from 2023 so those also will fail. Only 2022.3.62 will work correctly.

@DaXcess

DaXcess commented Oct 6, 2025

Copy link
Copy Markdown
Contributor Author

This one got merged a 'lil too quickly, I was proposing the IIsFileCreated abstraction, but not fully implemented it yet. Should've probably converted it back into a draft.

Will scramble together another PR (draft this time) that fixes some of the missing implementations in this one.

@DaXcess DaXcess deleted the pinvoke-download branch October 6, 2025 07:23
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

Successfully merging this pull request may close these issues.

IsFileCreated crash on Unity 2022.3.62 Wrong URL for pdb install?

3 participants