Jump to content

Cross Mod Function Calls


eXecator

Recommended Posts

I guess i wasnt very forthcoming with what I'm trying to do and my opening post wasnt very clear either.

 

So here's the deal. I encountered this problem in two places I found interesting.

  1. trying to offer support for mod deinstallation
  2. trying to offer easy ways to manipulate templates

 

In both situations I will end up needing to call code from a Mod which I dont know yet. I guess thats what you get if you try to offer framework functionalities. :wink:

 

For 1) I think it would be nice to have a way to "uninstall" a Mod from a savegame. I know its possible to remove a Mod from the list of needed DLCs and in doing so allow the savegame to be loaded without it. But anything the Mod did during its lifetime is still there. For instance anything done in X2DownloadableContentInfo's OnLoadedSavedGame() or InstallNewCampaign(). So to give Mods a way to cleanup, i'd like to let them define a function somewhere/somehow which I can call when time has come.

 

For 2) I had this Idea of offering an easy way to manipulate Templates. This comes up often. Since doing it right might be tricky and all solutions known to man are at least somewhat hacky I thought it would be nice to have it done in one place only. http://forums.nexusmods.com/index.php?/topic/3830880-mod-easy-template-modifications/

I currently have this Mod running localy, which allows my other Mods to add abilites to characters by just adding some ini lines. Which is quite the improvement compared to setting up a screen listener and doing the legwork. But for more involved template modifications it would be the easiest to let the other Mods define something like

function X2WhateverTemplate ApplyMyWhateverModification(X2WhateverTemplate Template)
{
  // do stuff with Template

  return Template;
}

those functions I would need to identify and call. An ini file could include hints on where to look, like

+Modifications=(Target="Whatever", ModifyingFunction="ApplyMyWhateverModification")

Right now I think I can solve 1) with a very hacky approach that I mentioned briefly in my opening post. To solve 2) I would need to be able to not only call any function, but on which takes a X2DataTemplate and returns one.

Edited by eXecator
Link to comment
Share on other sites

One option you can use is eventing. It'll depend on exactly what, if any info you need to pass between your mod and the 3rd party mods, but if there isn't any or if it's very limited you can document that you'll trigger some event at particular times and interested mods can listen for it. You can pass base game information and built-in types through the event arguments, but if you need anything more complex involving your own types it'll be harder.

 

If you need that you can publish your source and other mod authors can install that into the SDK source folder, parallel to XComGame. Then as far as third party mods are concerned, the package for your mod is basically part of the base game, just like XComGame or Engine. They can reference anything from their projects and it should just work - provided your mod package is actually there as a dependency at runtime.

Link to comment
Share on other sites

[...]

If you need that you can publish your source and other mod authors can install that into the SDK source folder, parallel to XComGame. Then as far as third party mods are concerned, the package for your mod is basically part of the base game, just like XComGame or Engine. They can reference anything from their projects and it should just work - provided your mod package is actually there as a dependency at runtime.

 

Wow if that works, i'll be super happy =)

 

I'll try that asap

Link to comment
Share on other sites

Sadly I cant make it work. Heres what I got.

  • two Mod Projects called FriendlyMod and XMod
  • FriendlyMod contains a class FriendlyInterface which i'd love to acces from XMod
  • this file exists: ...\XCOM 2 SDK\Development\Src\FriendlyMod\Classes\FriendlyMod.uc

 

I tried arround a lot but didnt make much progress. The only way I managed to get ModBody to somewhat compile XMod without complaining about not knowing type 'FriendlyInterface' yields this schizophrenic result:

Success - 0 error(s), 6 warning(s) (0 Unique Errors, 6 Unique Warnings)
Execution of commandlet took:  8.80 seconds
Done executing task "CompileScripts" -- FAILED.

This was "accomplished" with an added entry to XComEngine.ini

+NativePackages=FriendlyMod

Currently I'm out of ideas.

 

Has anyone successfully accessed a type from another package (baring XComGame stuff)?

Edited by eXecator
Link to comment
Share on other sites

It should work. It's effectively the same technique we used for a lot of EW mods. We didn't have the sources for the base game, so if we wanted to call stuff from source packages we created we needed to build a fake XComGame package containing the classes and functions we needed. So we just built a lot of stub classes with empty function definitions so that the compiler will find them and generate the correct import lists in the real mod package. The stub package and source isn't distributed, it's only needed to satisfy the compiler. The mod package will find the real versions at runtime. The only risk is that they get out of sync - if you break your interface and other mods are still compiling against the old version, you'll get bad results (mostly crashes) at runtime.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...