mirror of
				https://github.com/coop-deluxe/sm64coopdx.git
				synced 2025-10-30 08:01:01 +00:00 
			
		
		
		
	Add HOOK_ON_ADD_SURFACE and HOOK_ON_CLEAR_AREAS (#843)
	
		
			
	
		
	
	
		
	
		
			Some checks are pending
		
		
	
	
		
			
				
	
				Build coop / build-linux (push) Waiting to run
				
			
		
			
				
	
				Build coop / build-steamos (push) Waiting to run
				
			
		
			
				
	
				Build coop / build-windows-opengl (push) Waiting to run
				
			
		
			
				
	
				Build coop / build-windows-directx (push) Waiting to run
				
			
		
			
				
	
				Build coop / build-macos-arm (push) Waiting to run
				
			
		
			
				
	
				Build coop / build-macos-intel (push) Waiting to run
				
			
		
		
	
	
				
					
				
			
		
			Some checks are pending
		
		
	
	Build coop / build-linux (push) Waiting to run
				
			Build coop / build-steamos (push) Waiting to run
				
			Build coop / build-windows-opengl (push) Waiting to run
				
			Build coop / build-windows-directx (push) Waiting to run
				
			Build coop / build-macos-arm (push) Waiting to run
				
			Build coop / build-macos-intel (push) Waiting to run
				
			This commit is contained in:
		
							parent
							
								
									b99f18dacc
								
							
						
					
					
						commit
						838fe40d6e
					
				
					 8 changed files with 40 additions and 3 deletions
				
			
		|  | @ -7822,7 +7822,9 @@ HOOK_ALLOW_FORCE_WATER_ACTION               = 53 --- @type LuaHookedEventType | |||
| HOOK_BEFORE_WARP                            = 54 --- @type LuaHookedEventType | ||||
| HOOK_ON_INSTANT_WARP                        = 55 --- @type LuaHookedEventType | ||||
| HOOK_MARIO_OVERRIDE_FLOOR_CLASS             = 56 --- @type LuaHookedEventType | ||||
| HOOK_MAX                                    = 57 --- @type LuaHookedEventType | ||||
| HOOK_ON_ADD_SURFACE                         = 57 --- @type LuaHookedEventType | ||||
| HOOK_ON_CLEAR_AREAS                         = 58 --- @type LuaHookedEventType | ||||
| HOOK_MAX                                    = 59 --- @type LuaHookedEventType | ||||
| 
 | ||||
| --- @alias LuaHookedEventType | ||||
| --- | `HOOK_UPDATE` | ||||
|  | @ -7882,6 +7884,8 @@ HOOK_MAX                                    = 57 --- @type LuaHookedEventType | |||
| --- | `HOOK_BEFORE_WARP` | ||||
| --- | `HOOK_ON_INSTANT_WARP` | ||||
| --- | `HOOK_MARIO_OVERRIDE_FLOOR_CLASS` | ||||
| --- | `HOOK_ON_ADD_SURFACE` | ||||
| --- | `HOOK_ON_CLEAR_AREAS` | ||||
| --- | `HOOK_MAX` | ||||
| 
 | ||||
| ACTION_HOOK_EVERY_FRAME = 0 --- @type LuaActionHookType | ||||
|  |  | |||
|  | @ -3439,7 +3439,9 @@ | |||
| | HOOK_BEFORE_WARP | 54 | | ||||
| | HOOK_ON_INSTANT_WARP | 55 | | ||||
| | HOOK_MARIO_OVERRIDE_FLOOR_CLASS | 56 | | ||||
| | HOOK_MAX | 57 | | ||||
| | HOOK_ON_ADD_SURFACE | 57 | | ||||
| | HOOK_ON_CLEAR_AREAS | 58 | | ||||
| | HOOK_MAX | 59 | | ||||
| 
 | ||||
| ### [enum LuaActionHookType](#LuaActionHookType) | ||||
| | Identifier | Value | | ||||
|  |  | |||
|  | @ -149,6 +149,8 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh | |||
| | HOOK_BEFORE_WARP | Called before the local player warps. Return a table with `destLevel`, `destArea`, `destWarpNode`, to override the warp | `integer` destLevel, `integer` destArea, `integer` destWarpNode, `integer` arg | | ||||
| | HOOK_ON_INSTANT_WARP | Called when the local player goes through an instant warp.| `integer` area, `integer` id, `Vec3s` displacement| | ||||
| | HOOK_MARIO_OVERRIDE_FLOOR_CLASS | Called when Mario's floor class logic updates, return a `SURFACE_CLASS_*` constant to override the type. | [MarioState](../structs.md#MarioState) mario, `integer` surfaceClass | | ||||
| | HOOK_ON_ADD_SURFACE | Called when collision surfaces are added. | [Surface](../structs.md#Surface) surface, `boolean` dynamic | | ||||
| | HOOK_ON_CLEAR_AREAS | Called when a level's areas are unloaded. | None | | ||||
| 
 | ||||
| ### Parameters | ||||
| 
 | ||||
|  |  | |||
|  | @ -245,6 +245,8 @@ static void add_surface(struct Surface *surface, s32 dynamic) { | |||
|             add_surface_to_cell(dynamic, cellX, cellZ, surface); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     smlua_call_event_on_add_surface(surface, dynamic); | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  |  | |||
|  | @ -215,6 +215,8 @@ void load_obj_warp_nodes(void) { | |||
| } | ||||
| 
 | ||||
| void clear_areas(void) { | ||||
|     smlua_call_event_hooks(HOOK_ON_CLEAR_AREAS); | ||||
| 
 | ||||
|     struct NetworkPlayer* np = gNetworkPlayerLocal; | ||||
|     if (np != NULL) { | ||||
|         np->currAreaSyncValid = false; | ||||
|  |  | |||
|  | @ -3254,7 +3254,9 @@ char gSmluaConstants[] = "" | |||
| "HOOK_BEFORE_WARP=54\n" | ||||
| "HOOK_ON_INSTANT_WARP=55\n" | ||||
| "HOOK_MARIO_OVERRIDE_FLOOR_CLASS=56\n" | ||||
| "HOOK_MAX=57\n" | ||||
| "HOOK_ON_ADD_SURFACE=57\n" | ||||
| "HOOK_ON_CLEAR_AREAS=58\n" | ||||
| "HOOK_MAX=59\n" | ||||
| "ACTION_HOOK_EVERY_FRAME=0\n" | ||||
| "ACTION_HOOK_GRAVITY=1\n" | ||||
| "ACTION_HOOK_MAX=2\n" | ||||
|  |  | |||
|  | @ -164,6 +164,26 @@ void smlua_call_event_on_hud_render_behind(void (*resetFunc)(void)) { | |||
| 
 | ||||
| } | ||||
| 
 | ||||
| void smlua_call_event_on_add_surface(struct Surface* surface, bool dynamic) { | ||||
|     lua_State* L = gLuaState; | ||||
|     if (L == NULL) { return; } | ||||
| 
 | ||||
|     struct LuaHookedEvent* hook = &sHookedEvents[HOOK_ON_ADD_SURFACE]; | ||||
|     for (int i = 0; i < hook->count; i++) { | ||||
|         // push the callback onto the stack
 | ||||
|         lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); | ||||
| 
 | ||||
|         // push surface and dynamic
 | ||||
|         smlua_push_object(L, LOT_SURFACE, surface, NULL); | ||||
|         lua_pushboolean(L, dynamic); | ||||
| 
 | ||||
|         // call the callback
 | ||||
|         if (0 != smlua_call_hook(L, 2, 0, 0, hook->mod[i])) { | ||||
|             LOG_LUA("Failed to call the event_hook callback: %u", HOOK_ON_ADD_SURFACE); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void smlua_call_event_hooks_bool_param(enum LuaHookedEventType hookType, bool value) { | ||||
|     lua_State* L = gLuaState; | ||||
|     if (L == NULL) { return; } | ||||
|  |  | |||
|  | @ -70,6 +70,8 @@ enum LuaHookedEventType { | |||
|     HOOK_BEFORE_WARP, | ||||
|     HOOK_ON_INSTANT_WARP, | ||||
|     HOOK_MARIO_OVERRIDE_FLOOR_CLASS, | ||||
|     HOOK_ON_ADD_SURFACE, | ||||
|     HOOK_ON_CLEAR_AREAS, | ||||
|     HOOK_MAX, | ||||
| }; | ||||
| 
 | ||||
|  | @ -180,6 +182,7 @@ int smlua_hook_custom_bhv(BehaviorScript *bhvScript, const char *bhvName); | |||
| void smlua_call_event_hooks(enum LuaHookedEventType hookType); | ||||
| void smlua_call_event_on_hud_render(void (*resetFunc)(void)); | ||||
| void smlua_call_event_on_hud_render_behind(void (*resetFunc)(void)); | ||||
| void smlua_call_event_on_add_surface(struct Surface* surface, bool dynamic); | ||||
| void smlua_call_event_hooks_bool_param(enum LuaHookedEventType hookType, bool value); | ||||
| void smlua_call_event_hooks_bool_param_ret_bool(enum LuaHookedEventType hookType, bool value, bool* returnValue); | ||||
| void smlua_call_event_hooks_mario_param(enum LuaHookedEventType hookType, struct MarioState* m); | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 djoslin0
						djoslin0