-
Notifications
You must be signed in to change notification settings - Fork 207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added compatibility with mods that inject into PP-related vanilla functions #591
Conversation
It's related to how CM also gets a static copy of |
Just thinking out loud here: is there a way to create a "Create Sim-copy" function that can then be called on each Game function to create one where everything is replaced? Edit: just saw that in the commit you replace |
Another problem I just thought of is that using |
Not as broad as that, but you can use the same method I used to automate that. new Function(
`return ${Game.anyFunction.toString()
.replaceAll(/Game/, 'CM.Sim')}`,
)(); In an even more automated way: const gameObjKeys = Object.keys(Game);
const gameObjValues = Object.values(Game);
const CM.Sim = {};
gameObjValues.forEach((originalValue, index) => {
let injectedFunc;
if (typeof originalFunc === 'function') {
injectedFunc = new Function(
`return ${originalValue.toString()
.replaceAll(/Game/, 'CM.Sim.')}`,
)();
}
Object.assign(CM.Sim, {
[gameObjKeys[index]]: injectedFunc || originalValue,
})
}) That should create a copy of Game with all Game methods changed to CM.Sim, (might need some checking to make sure nothing was changed unintentionally) though it'd probably lag a bit since that's pretty much going through the entire game. Creating CM.Sim functions in this
For that, it is best to disable no-new-func rule. You already need to disable quite a few rules to work with Orteil code and ESLint. And Are eval() and new Function() the same thing? |
Should indeed be able to do this somewhat automated, although I think I prefer doing it on a per-function basis instead of the full game at once. We could put the replacing functions into Currently I am only using the |
I have worked on this some more and have implemented code that recognizes content mods in #592. Please do tell if any issues remain, but from my personal testing it all seems to work now! |
Though I just noticed that Cookie Monster would also break with kitten upgrades, checking that.