Sheep-y / Modnix

Mod loader and manager for Phoenix Point (Game).
https://www.nexusmods.com/phoenixpoint/mods/43
MIT License
12 stars 7 forks source link

Some users need to unblock Modnix to be able to see/edit Configuration #33

Open mad2342 opened 3 years ago

mad2342 commented 3 years ago

I use the excellent option to have a class in my Assembly that Modnix parses to provide the configuration view for editable settings. I had many posts on nexus on how to configure "Assorted Adjustments", it seems that quite a lot of users need to "unblock" Modnix for the Config-Tab to be shown at all. It's fixable on the users side following this guide: https://stackoverflow.com/questions/28339116/not-allowed-to-load-assembly-from-network-location but if possible would be better to workaround/fix on programs side as fiddling with .NET settings isn't really reliable for the end-users. I can't provide more details, unfortunately, as i never had the issue myself. I'll point people to this issue though, if you're fine with that? Thx alot and best regards, Mad

mad2342 commented 3 years ago

New info: A user reported that a mod of yours "Independent Gear" shows the config just fine, while mine won't. I had a look at the changes and your impentation of loading the settings is different indeed. I followed your guide in the WIKI and my stuff looks like this:

namespace AssortedAdjustments
{
    public static class AssortedAdjustments
    {
        internal static Settings Settings;

        // Modnix Entrypoints
        public static void SplashMod(Func<string, object, object> api)
        {
            Settings = api("config", null) as Settings ?? new Settings();
            (...)

with Settings:

namespace AssortedAdjustments
{
    internal class Settings
    (...)

Only potential problem could be the different entrypoint? (Splash vs. Main)?

Sheep-y commented 3 years ago

I read on Discord that the second config issue has been solved, so I'll focus on the first.

In order to properly load a mod's config class, Modnix need to create a .Net sandbox to load the mod. This sandbox protects Modnix from crash, and keep the mod dll free from file lock so that it is updatable, deletable etc. The loadFromRemoteSources config affects this sandbox.

As of Modnix 2.5.4 and Modnix 3 Beta 1, the config file will be created when the sandbox failed to initiate. The unfortunately news is I can't reproduce it. I tried marking installer and installed Modnix as Downloaded from Internet, and it still runs ok after the unlock prompt. I also tried marking the the mod, which create another Exception that is not solved by the loadFromRemoteSources config.

So, what I can do now, is to create the config anyway during startup, and add it to manual install package. Also Modnix can check on launch whether the config exists and, if not, create it and restart (if created). This should make sure Modnix is under the effect of loadFromRemoteSources.

As for the exception when the mod is marked as downloaded, for now the workaround is to remove the mark from the dll. Usually done by right-clicking it and select properties, but the Add Mod button also works.

I am seeing how Modnix can remove the mark. For reference, this is the error I got in the config panel:

System.IO.FileLoadException: Could not load file or assembly 'file:///C:\Users\Sheepy\Documents\My Games\Phoenix Point\Mods\PhoenixPt_DumpData\PhoenixPt_DumpData.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
File name: 'file:///C:\Users\Sheepy\Documents\My Games\Phoenix Point\Mods\PhoenixPt_DumpData\PhoenixPt_DumpData.dll' ---> System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at Sheepy.Modnix.MainGUI.Sandbox.LoadDll(String path)
Sheep-y commented 3 years ago

Here is a Modnix 3 development build that implements all the changes I laid above. From my testing it is able to unblock and read/write config of web-blocked mods.

ModnixInstaller_v3_20210111.zip

Sheep-y commented 3 years ago

Zyxpsilon and mad2342 confirmed that the build is working. The changes have been backported and released with v2.5.5.

pleszczy commented 3 years ago

Tried it on v2.5.6 and the same thing with 'This release of the .NET Framework does not enable CAS policy' happened.

It only started working after following that configuration suggestion from stack overflow.

<configuration>
    <runtime>
       <loadFromRemoteSources enabled="true"/>
   </runtime>
</configuration>
Sheep-y commented 3 years ago

@pleszczy Hi. Sorry to hear that it is still an issue. May I know:

  1. Was your change made to machine.config in the .net config folder?
  2. Was the Modnix setup / update done automatically or manually?
  3. Does a Modnix.conf file exists in the same folder as Modnix.exe
  4. If yes, does it have the same content (loadFromRemoteResource) and does it have the same name as the exe?

If the answer to question 3 or 4 is no, i.e. if the conf file does not exist or it is empty, it would be nice to have the setup log too.

pleszczy commented 3 years ago

@pleszczy Hi. Sorry to hear that it is still an issue. May I know:

  1. Was your change made to machine.config in the .net config folder?
  2. Was the Modnix setup / update done automatically or manually?
  3. Does a Modnix.conf file exists in the same folder as Modnix.exe
  4. If yes, does it have the same content (loadFromRemoteResource) and does it have the same name as the exe?

If the answer to question 3 or 4 is no, i.e. if the conf file does not exist or it is empty, it would be nice to have the setup log too.

I've started from scratch and documented the process step by step. This should help you reproduce it and also answer the questions above.

Steps to reproduce

{
  "SettingVersion": 20200428,
  "LogLevel": 15,
  "LogMonitor": false,
  "CheckUpdate": true,
  "LastCheckUpdate": "2021-02-09T16:20:28.2183637+01:00",
  "UpdateChannel": "dev",
  "GamePath": "F:\\SteamLibrary\\steamapps\\common\\Phoenix Point",
  "ModInfoWeight": -1.0,
  "ModListWeight": -1.0,
  "MinifyLoaderPanel": false,
  "MinifyGamePanel": true,
  "MaximiseWindow": false,
  "WindowLeft": -1.0,
  "WindowTop": -1.0,
  "WindowWidth": -1.0,
  "WindowHeight": -1.0,
  "OfflineParameter": "",
  "SteamCommand": "steam://rungameid/839770",
  "GogExe": null,
  "GogParameter": "/gameId=1795581746 /command=runGame /path=\"%GAME_PATH%\"",
  "EgsCommand": "com.epicgames.launcher://apps/Iris?action=launch",
  "EgsParameter": "",
  "Mods": null
}
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <runtime>
        <loadFromRemoteSources enabled="true"/>
    </runtime>
</configuration>
System.IO.FileLoadException: Could not load file or assembly 'file:///C:\Users\Piotr\Documents\My Games\Phoenix Point\Mods\Modnix.exe' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
File name: 'file:///C:\Users\Piotr\Documents\My Games\Phoenix Point\Mods\Modnix.exe' ---> System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.

   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile, Evidence securityEvidence)
   at System.Activator.CreateInstanceFromInternal(String assemblyFile, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo)
   at System.AppDomain.CreateInstanceFrom(String assemblyFile, String typeName)
   at System.AppDomain.CreateInstanceFromAndUnwrap(String assemblyName, String typeName)
   at System.AppDomain.CreateInstanceFromAndUnwrap(String assemblyName, String typeName)
   at Sheepy.Modnix.MainGUI.Sandbox.CreateSandbox()
pleszczy commented 3 years ago

Steps to fix it

4
<runtime>
       <loadFromRemoteSources enabled="true"/>
</runtime>
5 6 7

Though this has a side effect of breaking nordVPN and openHardwareMonitor. theyll complain that there is an unknown configuration present in the machin config

Sheep-y commented 3 years ago

Thanks pleszczy, that is very detailed. And thanks for the English message.

The reason I asked the info is because the last time I could reproduce it, it could be fixed with the local config, thus I consider it fixed. Apparently not for everyone.

I definitely can't reproduce it on my development and gaming pc, hard as I try, so I'll see if I can reproduce it on the cleanest pc in my home.

Sheep-y commented 3 years ago

Happy Chinese New Year! I am back! Who wants red pockets?

I tried running Modnix 3 Beta 3 on a "clean" media/gaming machine on an unprivileged account, with my own AA build, still can't reproduce the error. Will try mad's release next and, failing that, a totally clean Win 7 VM.

I start to think it may be related with Windows languages because I remember the previous config issue was also reported on a non-English platform. In that case it may be more difficult to test. We'll see. I thought I don't assume any system paths, but shall double check too.

Sheep-y commented 3 years ago

Did all I can. Create a new Win 10 1809 VM, make it Japanese, downloaded Modnix and Assorted Adjustment .

Modnix will fail to enable Add Mod button on first launch, which will be fixed. The Add Mod button is enabled on subsequence launch, and can install the zip, and can show the config.

I'll try a little bit more, but unless there is a breakthrough I'll stop the report here. Consider this issue "Cannot Reproduce", but I'm leaving this open for visibility.

Aghiuta2 commented 3 years ago

Had to make an account to add my two cents. All the program editing and .NET and all that went a bit above my head, while trying to solve this issue. But since my 286 days I know that sometimes just checking all tabs/files/setting, might lead to a solution. So I found that if you right click on the Modnix.exe file -> select Properties -> at the very bottom (check photo) there will be a button labeled Unblock, click that and after that the installed Modnix will allow proper viewing of the config section. image