Skip to content
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

Postload Scripts #158

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open

Postload Scripts #158

wants to merge 1 commit into from

Conversation

Nathan-MV
Copy link

Scripts that load before rgss_main

@WaywardHeart
Copy link

Joiplay calls this functionality postload scripts. The way they decide when to run them looks a little error prone to me, but it'd be a good starting point if you wanted to expand this to work for XP and VX.

You should also note in the config file that it's only for Ace games, unless you manage to fix that.

@Splendide-Imaginarius
Copy link

Joiplay calls this functionality postload scripts.

Alright then, if Joiplay did it first, I guess we should use the name they picked so that we don't cause unnecessary fragmentation. It's not a bad name either.

@Splendide-Imaginarius
Copy link

The way they decide when to run them looks a little error prone to me, but it'd be a good starting point if you wanted to expand this to work for XP and VX.

I'm not going to block this PR on XP/VX compatibility, but I would definitely be amenable to merging a follow-up PR that adds support for those. The Joiplay logic you linked looks rather scary; I'm guessing there's a less crazy way to do it, but maybe they know something I don't.

@Splendide-Imaginarius
Copy link

You should also note in the config file that it's only for Ace games, unless you manage to fix that.

Yes please note this.

@Nathan-MV Nathan-MV changed the title Plugin Scripts Postload Scripts Jan 22, 2024
@WaywardHeart
Copy link

WaywardHeart commented Jan 23, 2024

The Joiplay logic you linked looks rather scary; I'm guessing there's a less crazy way to do it, but maybe they know something I don't.

$scene appears to simply be an instance of a game-defined class with a main method on it, so... I think the only "good" way of hooking it is to monkey patch the base class constructor. Here's an example written in ruby, because it was easier.

Postload scripts monkey patch for XP/VX
postloadScriptsRan = false
baseClassNew = Class.instance_method(:new)

mainWrapperModule = Module.new
mainWrapperModule.send(:define_method, :main) {|*args, &block|
	if (!postloadScriptsRan && $scene.equal?(self))
		postloadScriptsRan = true
		mainWrapperModule.send(:remove_method, :main)
		
		# Comment this out if you're concerned about some other maniac messing with
		# the Class#new method
		Class.send(:define_method, :new, baseClassNew)
		
		System.run_postload
	end
	
	return super(*args, &block)
}

Class.send(:define_method, :new) {|*args, &block|
	ret = baseClassNew.bind(self).call(*args, &block)
	
	if (!postloadScriptsRan && self.method_defined?(:main))
		ret.singleton_class.send(:include, mainWrapperModule)
	end
	
	return ret
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants