Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.9.1a is out! (05/10/19); Blog post: Painting the Stars (02/07/20)

Pages: 1 [2]

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

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 15992
    • 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

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1019
    • View Profile
    • Email
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

  • Captain
  • ****
  • Posts: 316
    • 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.
Pages: 1 [2]