cmkushnir / NMSModBuilder

No Man's Sky Mod Builder
GNU Affero General Public License v3.0
53 stars 4 forks source link

Unable to initialize pre-NEXT versions of libMBIN. #10

Closed tractorbeam0 closed 1 year ago

tractorbeam0 commented 1 year ago

The older libMBIN downloading process goes fine, but it comes up with a strange issue with on initialization of it. It works entirely fine on modern versions, at least the current update.

[12:37:09.705] Loading Types from .\libMBIN.dll 4.37.0.1
[12:37:09.922] Loaded Types from .\libMBIN.dll 4.37.0.1: 622 enum's, 2227 classes, 18787 fields
[12:37:15.417] Select GoG, Steam, Xbox Game Pass, or Folder Select to load a Game Instance ...
[12:37:41.016] Creating cmk.NMS.Game.Data from C:\Users\gavat\OneDrive\Desktop\No Man's Sky\LegacyVersions\no_mans_sky_v1.38\
[12:37:41.016] Incorrect libMBIN.dll for selected game, have 4.37.0.1 need 1.38.3.
May prompt to download required libMBIN.dll, but it wil have wrong name and cannot be hot swapped with loaded libMBIN.dll.
Need to close app and manually update; will continue with reduced functionality.
[12:37:41.191] Loading Types from .\MBINCompiler_v1.38.3.dll 1.38.3
[12:37:41.223] Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)
   at CallSite.Target(Closure , CallSite , Object )
   at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
   at cmk.NMS.MBINC.TypeInfo..ctor(MBINC MBINC, MemberInfo MEMBER_INFO)
   at cmk.NMS.MBINC.ClassInfo..ctor(MBINC MBINC, Type TYPE)
   at cmk.NMS.MBINC.LoadTypes()
   at cmk.NMS.MBINC.LoadReleaseLocked(Release RELEASE)
[12:37:41.225] System.NullReferenceException: Object reference not set to an instance of an object.
   at cmk.NMS.Game.Data.get_LanguageId()
   at cmk.NMS.Game.Data.CreateAsync(Data LOCATION)
   at cmk.NMS.Game.Data.SelectAsync()
   at cmk.NMS.Game.Location.Buttons.ButtonClick(ImageButton SENDER)
cmkushnir commented 1 year ago

https://github.com/cmkushnir/NMSModBuilder#libmbindll "A given NMSMB version can only roll the libmbin.dll version forward."

The app is compiled against a specific version of libmbin, and can only use that version or newer. Even newer libmbin versions may not work if classes, functions, fields that the app code explicitly uses have changed. In order to mod an old version of the game you'd need a version of nmsmb that is coded to use the older libmbin|mbincompiler.

However, to view older mbin's you can use any nmsmb as it will load the correct libmbin at runtime and use reflection to "do the right thing". The reason the same mechanism isn't used to support modding w/ older libmbin is due to the amount of reflection required and differences that have occured throughout libmbin lifetime.

I did start down the path of trying to support modding w/ older libmbin, but didn't finish it. There are 3 general areas where libmbin is used: 1) To populate the lookup tabs, like products. This will likely always require a specific range of libmbin versions for a given nmsmb version. 2) Loading mbin's and converting to text for viewing. This loads the correct libmbin version at runtime. No change needed. 3) Using the correct libmbin when compiling and executing mods. Currently requires the libmbin from 1) but would like it to work like 2). This is still a wip.

cmkushnir commented 1 year ago

"And I'm asking this now because I don't see anywhere else I could... might I ask how one would pack a custom texture into a modpack using your tools? There's no example scripts or documentation that I could find."

See: https://github.com/cmkushnir/NMSModBuilder/blob/main/Doc/Tab/ScriptMod/Readme.md#new "When you create | rename | delete a mod script the application will automatically create | rename | delete a subfolder with the same name as the script. e.g. ./Scripts/Mod/MyScript.cs will have a corresponding ./Scripts/Mod/MyScript/ folder. The subfolder is where you can put script specific loose files e.g. textures, audio, other files that are needed, but aren't generated, by the script. A dummy (Loose_Files) script is provided as somewhere to place loose files that should be added to the mod pak, but not tied to a script being enabled or not.

The path used for the loose files, when added to the mod pak, is relative to their script subfolder e.g. ./Scripts/Mod/MyScript/Dir1/Dir2/Item.ext would be added to the mod pak as DIR1/DIR2/ITEM.EXT."