Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Pages: 1 [2]

Author Topic: Releasing a mod that overwrites some files in the .api  (Read 3968 times)

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24114
    • View Profile
Re: Releasing a mod that overwrites some files in the .api
« Reply #15 on: October 19, 2019, 09:01:25 PM »

@NoFoodAfterMidnight: Another potential issue is that any exception that occurs within your code will look like it took place in vanilla code. That could make things very difficult to troubleshoot, especially for anyone who doesn't know about this aspect of your mod's implementation. It might be worth catching and re-throwing any error that occurs in your overriden API methods so you can add a message to the log about how your mod encountered an error.

Oh, that's a super good point, and, uh, that could really blindside me. Glad you brought it up, since I'm at least directly aware of it now.
Logged

NoFoodAfterMidnight

  • Ensign
  • *
  • Posts: 39
    • View Profile
Re: Releasing a mod that overwrites some files in the .api
« Reply #16 on: October 20, 2019, 11:45:46 AM »

@NoFoodAfterMidnight: Another potential issue is that any exception that occurs within your code will look like it took place in vanilla code. That could make things very difficult to troubleshoot, especially for anyone who doesn't know about this aspect of your mod's implementation. It might be worth catching and re-throwing any error that occurs in your overriden API methods so you can add a message to the log about how your mod encountered an error.

That's a great point, I didn't think about that. I've taught myself java up until now, exceptions/error reporting in any language is pretty complex, so to make sure I do it right and not butcher the error/stack trace, how would you guys do it?
Logged

Sundog

  • Admiral
  • *****
  • Posts: 1727
    • View Profile
Re: Releasing a mod that overwrites some files in the .api
« Reply #17 on: October 20, 2019, 05:47:39 PM »

Well, there's likely a more elegant solution, but what I had in mind was something like this:
Code: java
public class FleetFactoryV3 {
public static CampaignFleetAPI createFleet(FleetParamsV3 params) {
try {
myObject.doModStuff();

vanillaObject.doVanillaStuff();
} catch (Exception e) {
Global.getLogger(FleetFactoryV3.class).error("NoFoodAfterMidnight's difficulty mod encountered an error!");

throw e;
}
}
}
This would ensure that the game crashes and logs the stack trace as normal, only preceded by a message identifying you as the appropriate point of contact and leaving a clue about the stack trace referring to your modified API instead of the vanilla one.
This approach would fail if you were to modify a field (member variable) in such a way that it caused an exception somewhere that isn't wrapped in a try block, so I would be extra careful to avoid that.

Nick XR

  • Admiral
  • *****
  • Posts: 713
    • View Profile
Re: Releasing a mod that overwrites some files in the .api
« Reply #18 on: October 27, 2019, 06:30:10 PM »

Another concern would be security.  I'm pretty sure janino is running in a Security Manager constrained manner, but if an API altering mod could include some hostile code that could do all sorts of naughty things if the user is running in Admin mode (which probably a small % of people are).  All it would take is for someone to take over a popular defunct mod and inject that, or to make their own mod and include bad bits.

Something like this:  https://thehackernews.com/2018/11/nodejs-event-stream-module.html
Although NPM is a dumpster fire when it comes to security so finding an exploit related to NPM is easy.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24114
    • View Profile
Re: Releasing a mod that overwrites some files in the .api
« Reply #19 on: January 19, 2021, 12:15:30 PM »

Bit of a necro, but: added plugins that allow replacing FleetFactoryV3.createFleet() and DModManager's various .addDMods() methods.
Logged
Pages: 1 [2]