Fractal Softworks Forum

Please login or register.

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

Author Topic: Is it time to reconsider the stance on reflection?  (Read 1112 times)

Princess_of_Evil

  • Commander
  • ***
  • Posts: 197
    • View Profile
Is it time to reconsider the stance on reflection?
« on: March 30, 2023, 02:47:15 PM »

As a preface, I've modded a bunch of games over the last decade, and used reflection in every one that had code modding to begin with (Minecraft, Rimworld, Stardew Valley, Terraria…)

In each and every one, reflection is *necessary* if you want to do anything beyond simple (or fancy, really) items. Mods like IndustrialCraft, Create, Calamity, the Vanilla Expanded series, hell, Forge itself are *impossible* to make using only basic coding methods. And, while it can be kind of considered an API issue, the truth is, API never has and will never have everything a modder needs. Even games with deep modding integration and communication, like Rimworld (and it's genuinely built around the fact that people will mod it) don't have an API wide enough.
You claim that reflection makes mods unstable, but it doesn't. Badly used reflection can do it, but my literal decades of experience tell that players are quick to recognize and quietly ignore mods with subpar coding, and they rarely survive more than a version or two. What it really seems to be, from my modder perspective, is a simple "my code! mine! don't touch it!" impulse, which is a silly impulse to have in a game revolving around a modding community this much.


Logged
Proof that you don't need to know any languages to translate, you just need to care.

SafariJohn

  • Admiral
  • *****
  • Posts: 2796
    • View Profile
Re: Is it time to reconsider the stance on reflection?
« Reply #1 on: March 30, 2023, 02:57:20 PM »

I can easily think of two considerations far more important than "my code!" for Alex.

One: Starsector's reputation. If the game gets a bad rep and sales slow down, then Alex has to find another source of income which will drastically reduce the time he can spend on Starsector.

Two: bug reports. Alex already has to sift through many many bug reports caused by mods that get blamed on vanilla. If a number of mods were using reflection it would take even more of his time to determine whether a given error is caused by vanilla or by some mod mucking around in vanilla's code.
Logged

Draz

  • Ensign
  • *
  • Posts: 8
    • View Profile
Re: Is it time to reconsider the stance on reflection?
« Reply #2 on: March 30, 2023, 04:03:32 PM »

This is quite an aggressive and unkind tone to take, especially with someone that you want to convince to do something. I think you should consider deleting this thread, having a think and maybe trying again with a kinder and more constructive attitude if you really think it's important.
Logged

Ontheheavens

  • Lieutenant
  • **
  • Posts: 99
    • View Profile
Re: Is it time to reconsider the stance on reflection?
« Reply #3 on: March 30, 2023, 05:48:22 PM »

Reflection block doesn't seem like a real problem to me; you can work around it in a multitude of ways. What is real, painful obstacle both to modding and to debugging is obfuscation. Obfuscation is what makes about half of outstanding ideas unrealistic and un-implementable.

What it really seems to be, from my modder perspective, is a simple "my code! mine! don't touch it!" impulse, which is a silly impulse to have in a game revolving around a modding community this much.

That was my impression too, at first, but even if it is so, well, it's anything but silly. On the contrary, it's a very reasonable thing to do, from Alex's perspective, who is not a modder. The money flows, the modders make mods (even if they are chiefly superficial and shallow faction mods), so what's the problem? Some modder is discontent with his options? That's his own problem.

One: Starsector's reputation. If the game gets a bad rep and sales slow down, then Alex has to find another source of income which will drastically reduce the time he can spend on Starsector.

It is not entirely clear why Starsector would get a bad rep because of enabled reflection. Given the current situation, the prospect of Starsector getting a bad rep is quite unlikely, from my point of view.

This is quite an aggressive and unkind tone to take, especially with someone that you want to convince to do something. I think you should consider deleting this thread, having a think and maybe trying again with a kinder and more constructive attitude if you really think it's important.

Maybe you shouldn't have comment if all you have to contribute is tone policing?
Logged
 

xenoargh

  • Admiral
  • *****
  • Posts: 5031
  • naively breaking things!
    • View Profile
Re: Is it time to reconsider the stance on reflection?
« Reply #4 on: March 30, 2023, 07:13:35 PM »

Obfuscation is what makes about half of outstanding ideas unrealistic and un-implementable.

I think that the appropriate way to address this is to make an API request. Pretty much everything modders can do now was, at one point, requested. Alex has done an amazing job at exposing features over the years.

I think reflection's a double-edged sword with few benefits for a project like this, no offense meant to the OP; it makes it harder to maintain, debugging's harder, and it opens up more ways to have a modder to introduce scary stuff into their project, even by accident (copy-pasting something from a Github that they don't understand that provides access privileges that aren't appropriate, etc.).

We have enough people here who've picked up Java largely to mod this engine (including me), and they tend to be, well, newbies; this means a lot of copy-pasta code. Add in reflection... stir in somebody's file-access library meant for advanced developers... and you could have a situation where a person's OS got nuked, the modder in question is too ignorant to figure out why... and who's liable?
Logged
Please check out my SS projects :)
Xeno's Mod Pack

SafariJohn

  • Admiral
  • *****
  • Posts: 2796
    • View Profile
Re: Is it time to reconsider the stance on reflection?
« Reply #5 on: March 30, 2023, 08:00:00 PM »

One: Starsector's reputation. If the game gets a bad rep and sales slow down, then Alex has to find another source of income which will drastically reduce the time he can spend on Starsector.

It is not entirely clear why Starsector would get a bad rep because of enabled reflection. Given the current situation, the prospect of Starsector getting a bad rep is quite unlikely, from my point of view.

I think the risk to Starsector's reputation is tiny now, but when reflection was blocked Starsector was considerably less well known.
Logged

Princess_of_Evil

  • Commander
  • ***
  • Posts: 197
    • View Profile
Re: Is it time to reconsider the stance on reflection?
« Reply #6 on: March 30, 2023, 10:25:31 PM »

Obfuscation is annoying, but can be worked around. I would like to see it gone one way or another, though.
And before anyone says anything: All four games I've mentioned are not obfuscated. Minecraft is, technically, but they have official deobfuscation mappings you can freely use.
File access isn't a problem if mods can read each other, modify mod data in memory, or save data in their own folders and inside the save file. I know API is there for at least three of these things.
Reflection being a double-edged sword just isn't true. One of the games I mentioned is Rimworld, and the one library you see everyone use is Harmony. Which is a reflection library (specifically, it's about half of a mixin library - the half that's reasonable to code). It just shows that a) new modders won't use reflection because it's big and scary, even if easy guides are available; and b) the only thing unrestricted access to reflection gives you is fun and fancy mods.
Logged
Proof that you don't need to know any languages to translate, you just need to care.

tomatopaste

  • Captain
  • ****
  • Posts: 298
    • View Profile
Re: Is it time to reconsider the stance on reflection?
« Reply #7 on: March 31, 2023, 02:36:23 AM »

working around the api is more fun than the sledgehammer approach
Logged
Fast Engine Rendering | HexShields | Lights Out | Pearson Exotronics | Combat Misc Utils
indev: NĂ«utrino Corporation, Combat Multiplayer

Ruddygreat

  • Captain
  • ****
  • Posts: 419
  • Seals :^)
    • View Profile
Re: Is it time to reconsider the stance on reflection?
« Reply #8 on: March 31, 2023, 03:30:53 AM »

Two: bug reports. Alex already has to sift through many many bug reports caused by mods that get blamed on vanilla. If a number of mods were using reflection it would take even more of his time to determine whether a given error is caused by vanilla or by some mod mucking around in vanilla's code.

Honestly, I think that this is the main case against fully lifting the reflection block - I spend a lot of time helping to troubleshoot issues in the unofficial discord & if less experienced modders got their hands on reflection tools I'd probably end up going insane from trying to track down issues.
hell, we've already had an experienced modder mess up with reflection (sutopia's concord) & since his implementation wasn't perfect it caused a good number of chaos bugs, even breaking a couple vanilla features along the way.
This is even ignoring any compatibilty issues that might pop up if reflecton became more common; 2 mods patch something to work the way they need it to & now neither mod works, but both say the crash is in vanilla code.

And as a modder, tbh the reflection block never concerns me because the API is wide enough to do like 99% of the things you'd want to for most mods, most every mod that I've seen utilise reflection does so as a gimmick. (though, loosening the obfuscation would be nice to help replicate some vanilla effects)
And even then, if I wanted to join the 1% of modders using reflection, as others have said in other places, the reflection block is trivial to avoid if you know how to, so I'd just learn how to & it'd not be an issue anymore.


(and one last thing that bothered me)
And before anyone says anything: All four games I've mentioned are not obfuscated.

however- and this is a big point I think you've missed- none of them have official modding APIs, so reflection is necessary to get anything done, vs. the extensive API that starsector has.

Histidine

  • Admiral
  • *****
  • Posts: 4306
    • View Profile
    • Bitbucket profile
Re: Is it time to reconsider the stance on reflection?
« Reply #9 on: March 31, 2023, 03:35:12 AM »

In a post elsewhere, Alex's stated rationale for the current system was:

Yeah, it's a bit of grey area. Regarding the use of reflection, however, I would argue that restrictions as a security precaution is not a good idea in the first place, at least not in its current form.

This is based on the idea that an incomplete and easily bypassable security measure is worst than no security measure at all. It can lure users into a false sense of safety, when the fact is that running untrusted code from the Internet is fundamentally unsafe (unless it's in an industrial grade, battle-tested sandbox, like a modern browser).

I'm acutely aware of this, and the restrictions are not a security precaution (as you say, they're incomplete and basically entirely useless as that), and aren't presented to the player as such (or at all)! They're mainly there because it's fairly likely that your average modder could write file IO code that would mess up a user's system *by accident*. Even an otherwise excellent programmer could easily make a mistake like this if they don't have a properly careful mindset when writing, say, code that handles file deletion. So this is in place there to prevent half-baked attempts and signpost "don't do this" to someone with more experience that *could* bypass it. Someone malicious could find a way around pretty much no matter what, and this isn't concerned with that at all.

If there's some functionality that I could add to the API that would make life easier, btw, that'd be the best way to go - then I can put some effort into making sure that code is "safe" and more modders could benefit from being able to use it.

(the thread is for a mod that uses reflections; one of the posts on the first page hints at how)

So, supposing we accept that there should indeed be a 'do not use unless you have to' sign, how accessible should disregarding that sign be? For instance, could the "file access and reflection are not allowed" message include a one-sentence description of how to bypass it?
Logged

Princess_of_Evil

  • Commander
  • ***
  • Posts: 197
    • View Profile
Re: Is it time to reconsider the stance on reflection?
« Reply #10 on: March 31, 2023, 04:03:00 AM »

however- and this is a big point I think you've missed- none of them have official modding APIs, so reflection is necessary to get anything done, vs. the extensive API that starsector has.
Rimworld has an official API. They're allergic to interfaces, so it's entirely done through classes of questionable abstraction, but it's there. You can do quite a lot without any reflection at all. Just about as much as you can with Starsector's API. It's what you can't do with API that you need reflection for.

I know about the ways of going around the block, but one big problem about Starsector's blocks is that the already difficult to understand reflection code just blows up. Concord has non-obvious bugs just cause the ways around reflection block make the code nigh unreadable.
Also, reflection is slow as is and the "going around" part just makes it slower. It's fine if you're doing something that runs rarely, or with UI code where you can do everything once per tick and have normal code handle the slow stuff, but if there ever becomes a mod that seriously changes ship AI, the extra boilerplate can get ugly real fast.
And of course another is that i'm never sure whether Alex will ever just plug the hole.
Logged
Proof that you don't need to know any languages to translate, you just need to care.

basileus

  • Commander
  • ***
  • Posts: 131
    • View Profile
Re: Is it time to reconsider the stance on reflection?
« Reply #11 on: March 31, 2023, 06:09:02 AM »

I have taken a stance similar to yours in a standard's debate before, PoE.  A certain fruit derivative software company objected to the use of frozen arrays.  I pointed out that, in practice, to the extent it was an issue it would only be an issue for a very small number of framework/library maintainers, all of whom were likely to quickly grok frozen arrays.

Despite being philosophically inclined to agree with you, I'm not certain that I do in this case.  A significant number of mods are made by novices.  Many players use a large number of mods.  The tools for dependency management are extremely primitive, and come from the community.  These are largely volunteer efforts, and even some of the most ubiquitous and ambitious mods are understandably seeing their maintainers drift away.

Reflection for grey hat solutions is an inevitable source of technical debt.  In this particular community, the modding culture doesn't seem to be for people to use a small number of big mods maintained by teams of people; but rather, people using lots of mods, nearly always with a single maintainer.  To my mind, this greatly increases the risks of things like race conditions and performance problems; makes debugging a nightmare; and, would generally lower accessibility into the mod scene and make it more challenging for mods to find new maintainers.  Starsector is a very long tail game, and so most mods will probably need to change hands at some point if they are to survive.  There are advantages to a less technically demanding bar.

That said, there may be a middle ground.  I think the Lazy libraries point to it.  Feature mods should probably avoid implementing reflection.  Instead, there could be a very small number of middleware libraries or frameworks that provide a community API for other modders to use, and they could even use proper semantic versioning ( :P ).
Logged

Princess_of_Evil

  • Commander
  • ***
  • Posts: 197
    • View Profile
Re: Is it time to reconsider the stance on reflection?
« Reply #12 on: March 31, 2023, 06:47:58 AM »

I'm not against it being aggregated to a couple big library mods and a couple hardcore small tweak mods. That's usually how it goes anyway in other modding communities - as i've said before, less experienced modders are generally too afraid to touch reflection (for good reason).
Logged
Proof that you don't need to know any languages to translate, you just need to care.

Ontheheavens

  • Lieutenant
  • **
  • Posts: 99
    • View Profile
Re: Is it time to reconsider the stance on reflection?
« Reply #13 on: March 31, 2023, 08:26:14 AM »

Obfuscation is annoying, but can be worked around.

From what I've gathered, the only obfuscated classes that can be reasonably worked with are those that are close to the API surface, i.e. those that have at least some of their method names (or more) unobfuscated. Once you venture into regions several classes away from the surface, you realize that there is virtually nothing in terms of clues which could aid your reverse-engineering process - and to add insult to injury, IDE syntax recognition can fail here too because of obfuscated variables being substituted for Java keywords. In other words, the scenario of practically utilizing those deep obfuscated classes is unreasonably time-intensive, to the point of complete meaninglessness.

I sure would love to hear about methods of working around obfuscation that solve the considerations above.

I think that the appropriate way to address this is to make an API request. Pretty much everything modders can do now was, at one point, requested. Alex has done an amazing job at exposing features over the years.

Right, that's the usual, quite reasonable answer. I see the following issues with this:

  • There is no guarantee at all that your request is granted - in my experience, the answer can vary from "sure, added the methods" to "that'd be a bit of work, unlikely" and "no, not going to happen".
  • Even if it is considered/granted, the update cadence is in terms of years. Your code work will hang awaiting additions a considerable amount of time.
  • Finally, even if we disregard points above: this workflow introduces a bottleneck named Alex, because all the API requests/additions have to be processed and implemented by one developer which has 24 hours in a day just like the rest of us, while the combined work hours of the modding community is, I reckon, is well in the hundreds, if not thousands.
« Last Edit: March 31, 2023, 08:49:53 AM by Ontheheavens »
Logged
 

Princess_of_Evil

  • Commander
  • ***
  • Posts: 197
    • View Profile
Re: Is it time to reconsider the stance on reflection?
« Reply #14 on: March 31, 2023, 08:35:48 AM »

It's just pattern recognition, really. You do need an unobfuscated spot somewhere, but i haven't had the need to start without any logical entry points yet. From there, you just wander until you find a class that looks about right.
It definitely helps that a lot of code talks to each other using the same API we use. It also helps that a lot of game code tends to be either logically concentrated, or be UI code, which is very obvious in other ways (like the main classes for UI code having unobfuscated names).
Logged
Proof that you don't need to know any languages to translate, you just need to care.
Pages: [1] 2