================================== Explod Expansion Pack ==================================
ver. 2.24
by Choon_2i

---------------------------------- Preface ----------------------------------
WinMUGEN only. Uses a SuperNull file to add various functionalities to the Explod and ModifyExplod state controller.
These functionalities will persist until the engine is closed (unless it's overwritten by some other code).
If there's a problem, feel free to toss.

This version is a massive overhaul that replaces the functions responsible for Explod processing completely in lieu of hooking.
This has been tested against old versions of ExplodExpansion and Minor's Test_CreateStaCon.
No errors have been encountered during testing, so I think it works well enough?
I think this should also be more stable if placed on the p2 side due to switching to the default handler if non-expanded Explods are loaded.

You can use it freely (whether modifying/referring/otherwise), but credit is appreciated.
	You can also use the AIO loader freely. Code ends with a period (.) and non-coding characters are skipped over.
You can combine the StateDef in the DBO file with others as you wish.
	As it uses SJIS code, any editor with ANSI/Shift_JIS support should allow you to modify the file safely.

---------------------------------- How to Use it ----------------------------------
To execute the code, in the def file, put
st = ExplodExpansion.st ;in whatever folder you placed it in, and/or whatever it's renamed to
	Filename can be modified freely.
	The principle is to influence every Explod loaded after this, so we load this file first.
	However, if you know for a fact that you aren't using any Explods before this file, you may put it in st0/etc. as you see fit.
Executes upon launch. As this version uses FBOF, CMDOF, and DBOF simultaneously, it shouldn't be blocked under most circumstances.
	I believe the only exception to this is edits that block ALL exploits (TheCalpUlexicWorld, TierDefenseMan-R).
	You can always cheese it through pre-caching though.
NOTE: This is defined as StateDef -9.

---------------------------------- How to Tweak it ----------------------------------
[[[[PLANNED FEATURE]]]]

---------------------------------- Feature List ----------------------------------
Now that it's not just Explod Rotation, this section will list every feature that is implemented.

------------- Explod Rotation (v1.00+) -------------
Compatible with ModifyExplod.
Adds 3 parameters: angle(=float), angle.add(=float)(ModifyExplod-specific), moment(=float)

The classic.
You can see the glorious effects by simply defining "angle = whatever" in the Explod state controller itself.
This rotation is influenced by facing exactly as you'd expect from AngleDraw, but here's a brief summary if you aren't aware:
facing = +1 | vfacing = +1: Normal Rotation
facing = -1 | vfacing = +1: Inverted Rotation
facing = +1 | vfacing = -1: Inverted Rotation
facing = -1 | vfacing = -1: Normal Rotation
Shadows generated by these Explods will rotate in the same way

As of 2.00, another parameter has been added: moment.
This automatically changes the Explod's rotation every frame by the amount specified.
This means that the below 3 state controllers are equivalent:
-----------
[State Explod Only!]
type = Explod
trigger1 = !time
ID = 2
angle = 0
moment = 1
[State ModifyExplod Method]
type = ModifyExplod
trigger1 = 1
ID = 2
angle = time%360
[State Angle.Add Method]
type = ModifyExplod
trigger1 = 1
ID = 2
angle.add = 1
-----------
As a result, you don't have to actually call ModifyExplod every frame, which can be incredibly laggy.
If you still WANT to do this, however, Minor's addon, angle.add, is included in this version as well.

------------- BindTime=0 Support (v2.00+) -------------
Dubiously compatible with ModifyExplod.

In order to summon an Explod at the position of a player without it being tied to the player's position,
some weird workarounds have historically been used.
This change simply makes the below 2 state controllers equivalent:
-----------
[State BindTime=0]
type = Explod
trigger1 = !time
postype = p1
pos = 0, 0
facing = 1
bindtime = 0
[State PosType=Left]
type = Explod
trigger1 = !time
postype = left
pos = ceil(screenpos X), ceil(screenpos Y)
facing = facing
-----------
This method has the bonus of it not following the camera for a frame, though.
Very few people (I alone?) use bindtime = 0, so I'd imagine the impact is minimal.

NOTE: This will not work on the first frame of a round besides the first one ever started by the engine (gametime!=1) when postype=p1 or p2.
      As the workaround for this is far too complex to be worth the effort, I will not fix it.

------------- ModifyExplod Count (v2.00+) -------------
As you'd expect, ModifyExplod-only.
Adds 1 parameter: count(=int)

ModifyExplod will scan every single Explod, even if you only have one of them active, just to make sure that it finds all of them.
However, most of the time, you'll only ever use 1 Explod with a particular ID.
As a result, to reduce lag, you can now specify the amount of Explods that you wish to modify using the count parameter.
-----------
[State Just the first, please!]
type = ModifyExplod
trigger1 = 1
ID = 2
count = 1
pos = 0, 0
-----------
count=0 is default behavior.
count>0 will function as you'd expect.
count<0 will be treated as count>0, but start from the end of the Explod table. (useful for ontop=1)

-------------- Animation Adjustment (v2.00+) --------------
Compatible with ModifyExplod. In addition, makes the anim field compatible with ModifyExplod.
Adds 1 parameter: animelem(=int)
Built-in/expanded version of Minor's ModifyExplodAnim template.

You can now specify animelem alongside anim to determine the starting animation element of an Explod.
...in all honesty, this is mostly for ModifyExplod, which now additionally supports the anim and animelem parameters.
This is exceptionally useful for polymorphic animations, like the below:
-----------
[State Polymorph]
type = ModifyExplod
trigger1 = 1
ID = 2
count = 1
anim = anim
animelem = animelemno(0)
-----------
This allows you to not have to resummon an Explod every frame!

NOTE: If an invalid animation is specified with ModifyExplod, it will simply ignore the anim field.
      This does not modify Explod spawning behavior, which requires a valid anim.
NOTE: You cannot swap between F anims and non-F anims. If the incorrect one is specified, it will simply default to the correct one.

-------------- Anim Owner Specification (v2.00+) --------------
Incompatible with ModifyExplod.
Adds 2 new parameters: animowner(=int), spriteowner(=int)
Built-in/expanded version of Minor's Explod2 state controller.

When set to an explicit -1, default behavior is assumed. This is also the failsafe behavior for other cases.
When set to an explicit -2 and the user is thrown, it will use the throw owner's animations/sprites.
When set to anything else, it will use the player with the specified ID's animations/sprites.
	Mind that the above -1/-2 are explicit. If an enemy has an ID of -1, and you use enemy,ID, it will use the enemy's data as expected.
spriteowner defaults to animowner unless manually specified.
	I have attempted to prevent the redirect=death bug that exists with HitDef/etc. I'm not sure if I did.
For example:
-----------
[State CA2 With Extra Steps]
type = Explod
trigger1 = 1
ID = 2
anim = 6000
animowner = -2
spriteowner = -1
-----------
The above creates an Explod using the throw owner's anim 6000, but the user's sprite data.
If spriteowner = -1 is commented out, it will instead use the throw owner's.

This is mostly to allow for smoother direction.
Rather than using postype=p2 for effects during throws, you can use this in a throw state.
Alternatively, you can probably do some funny things if you know what you're doing... (sprite bug-type effects).

-------------- Automatic Scaling Adjustment (v2.00+) --------------
Compatible with ModifyExplod.
Adds 1 new parameter: growth(=floatX,floatY)

By specifying growth, on a per-frame basis, the scale of the Explod will be increased automatically.
Similar to scale, this is a comma separated list of x, y.
This means that the below 2 are essentially equivalent:
-----------
[State Explod Only!]
type = Explod
trigger1 = !time
ID = 2
scale = 0.5, 0.5
growth = 0.05, 0.05
[State ModifyExplod Method]
type = ModifyExplod
trigger1 = 1
ID = 2
scale = 0.5+time/20., 0.5+time/20.
-----------
Similar to moment, this is for lag reduction.

-------------- Manual LayerNo Specification (v2.00+) --------------
Compatible with ModifyExplod.
Adds 1 new parameter: layerno(=int)
Built-in version of Minor's Explodのontop=0.5化 template.

Exactly as it says on the tin. Can be 0~2.
layerno=0: Default behavior.
layerno=1: ontop=0.5 behavior.
layerno=2: ontop=1 behavior.
If ontop is specified and non-zero, this is ignored.

-------------- EnvShake Permission Specification (v2.00+) --------------
Compatible with ModifyExplod.
Adds 1 new parameter: doenvshake(=int)
Built-in version of Minor's ExplodのEnvShake無効化 template.

Exactly as it says on the tin.
doenvshake=1: Default beavhior.
doenvshake=0: Ignores the effects of EnvShake.

-------------- Facing Change Bugfix (v2.02+) --------------
ModifyExplod-only by technicality.

This pack fixes a bug that causes Explods to be unable to become un-flipped.
	For example, if you're facing right and summon a postype=p1,facing=-1 Explod, ModifyExplod cannot ever reset its facing.
If facing is unspecified, 
Note that facing changes only takes effect if postype is specified (default MUGEN behavior).
Ironically, this stems from a bug report by Kousa.

-------------- OwnPal Expansion (v2.20+) --------------
Incompatible with ModifyExplod.

You can now specify ownpal values that are greater than 1 to create a separate ownpal sprite array.
This array has similar behavior to ownpal=1, and interacts with AllPalFX in the same way.
Each array is specific to any player with the same sprites. Separate instances with the same ownpal number will use the same array.
Due to internal processing, this means that different instances of the same character will have different arrays.
While this is completely useless on the surface, it has great compatibility with the other features added this update. Namely,

-------------- Palette Source Specification (v2.20+) --------------
Compatible with ModifyExplod.
Adds 1 new parameter: palsource(=intGroup,intItem)

Any and all sprites rendered by this Explod will use the palette of the sprite with group intGroup and item intItem.
For example,
-----------
[State ]
type = Explod
trigger1 = !time
ownpal = 2
palsource = 69,420
-----------
Will change the Explod's palettes to match that of sprite 69,420.
The second argument can be omitted. If it is, it will be set to the corresponding player palette (as written in the def file) instead.
-1 can also be manually specified to disable it entirely. Note that this does not mean it will revert palettes to normal.
NOTE: This may additionally affect any Explods that share the same ownpal array, depending on if they use a palette modified this way.
      If ownpal=0 is used (or ownpal is omitted), the player's palettes will also be affected.
      If ownpal=1 specifically is used, any hitsparks created by the player may also be affected.

-------------- PalFX Specification (v2.20+) --------------
Compatible with ModifyExplod.
Adds the palfx parameters from HitDef/similar state controllers.
The mechanism of action is slightly different from the typical PalFX, so only sprites that share the same palette as the Explod will be affected.

Does exactly what you think it does. Namely, an Explod like the below:
-----------
[State ]
type = Explod
trigger1 = !time
ownpal = 2
palfx.time = 5
palfx.color = 0
-----------
Will make the Explod monochrome for 5 frames upon spawning.
This uses the palfx.#### format, of course.
NOTE: Similar to Palette Source Specification, this may additionally affect any Explods that share the same ownpal array.
      If ownpal=0 is used (or ownpal is omitted), the Explod's PalFX will have undefined behavior.
      If ownpal=1 specifically is used, the Explod's PalFX may also affect any hitsparks created by the player.

---------------- Changelog ----------------
v2.24: Fixed a memory leak that occurred on Shift+F4 after a character uses expanded ownpal values
v2.23: Added further safeguards to ensure that a PalFX struct would be defined on a per-Explod basis
       Fixed that a ModifyExplod with a count value less than 0 would function erratically
       Fixed that the previously installed version detection function didn't function correctly
v2.22: Fixed that spawning an ownpal=0 Explod without PalFX/palsource would interrupt the user's PalFX for 1 frame
       Fixed a rare crash that occurred at the start of the match due to attempting to reset the palettes of a freed SpriteArray
v2.21: Fixed that hitsparks would have shadows when they weren't supposed to
v2.20: Expanded ownpal functionality, added palsource and palfx
v2.11: Properly extended functionality to Minor's Explod2 State Controller
       Fixed a memory leak that happens when a character using ExplodExpansion's custom parameters is repeatedly reloaded
       Preemptively fixed the same memory leak when Explod2 is sideloaded
v2.10: Old versions of v2.00 onwards will now preserve old behavior rather than be overwritten
       Fixed that Minor's Explod2 State Controller crashed when ownpal=0 is specified
       Fixed that Minor's Explod2 State Controller's admin field had no effect
       Fixed that bindtime=0 didn't follow the camera when postype=p1/p2 is specified
v2.08: Fixed that v2.01 onwards will crash when an opponent with v1.01~v1.04 is loaded first
v2.07: Fixed that spriteowner would always be set to 0
v2.06: Fixed that not specifying animelem in a ModifyExplod would crash immediately
v2.05: Fixed that animelem instead specified animtime
       Fixed shadow handling breaking horribly
v2.04: Restored the default placement behavior of postype=front/right
v2.03: Fixed that ontop=1/layerno>0 Explods did not render properly in certain situations
v2.02: Fixed that ModifyExplod would result in the Explod not binding correctly
       Added the Facing Change Bugfix
v2.01: Re-fixed the bug that v1.01 fixed
       Fixed that bindtime=0 didn't function correctly
v2.00: Added various functionalities.
v1.04: Fixed that add1 Explods would replace the animation with the specified angle
v1.03: Fixed an environmental incompatability issue with previously loaded characters
v1.02: Fixed that previously loaded characters' Explods would rarely erroneously rotate
v1.01: Fixed that rotated animations with transparency require trans to be manually specified in order to display properly

------------ Future Plans (tm) ------------
subalpha
Modloading
I think that's it unless there's something else I find important

------------- Special Thanks! -------------
awino
	There's a particular blog post (http://blog.livedoor.jp/awino/archives/32907295.html) that inspired me to create this.
	Funnily enough, it was published exactly 1 month and 1 day before initial publication.
Minor
	Most new additions in v2.00 are somewhat based on their already existing templates.
	I've specified which ones in each section.
Kousa
	For bombarding me with bug reports and making sure this is the best it can be.
	Also unintentionally inspired a new feature.
and you for downloading

Hopefully you have fun using it!
~Choon_2i


