mirror of
https://github.com/Jackzmc/sourcemod-plugins.git
synced 2025-05-05 19:53:20 +00:00
Cleanup
This commit is contained in:
parent
39db71edd6
commit
59d4310a94
4 changed files with 0 additions and 1829 deletions
Binary file not shown.
|
@ -1,962 +0,0 @@
|
|||
#if defined _actions_included
|
||||
#endinput
|
||||
#endif
|
||||
|
||||
#define _actions_included
|
||||
|
||||
#define ACTION_NAME_LENGTH 32
|
||||
|
||||
enum ActionResultType
|
||||
{
|
||||
CONTINUE, // continue executing this action next frame - nothing has changed
|
||||
CHANGE_TO, // change actions next frame
|
||||
SUSPEND_FOR, // put the current action on hold for the new action
|
||||
DONE, // this action has finished, resume suspended action
|
||||
SUSTAIN, // for use with event handlers - a way to say "It's important to keep doing what I'm doing"
|
||||
};
|
||||
|
||||
enum EventResultPriorityType
|
||||
{
|
||||
RESULT_NONE, // no result
|
||||
RESULT_TRY, // use this result, or toss it out, either is ok
|
||||
RESULT_IMPORTANT, // try extra-hard to use this result
|
||||
RESULT_CRITICAL // this result must be used - emit an error if it can't be
|
||||
};
|
||||
|
||||
enum BehaviorAction
|
||||
{
|
||||
INVALID_ACTION
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Callback called for every entity action.
|
||||
*
|
||||
* @param action Action address
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
typedef ActionsIteratorCallback = function void (BehaviorAction action);
|
||||
|
||||
/**
|
||||
* @brief Called whenever action is created
|
||||
*
|
||||
* @param action Created action address
|
||||
* @param actor Actor of the action
|
||||
* @param name Name of the action
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
forward void OnActionCreated( BehaviorAction action, int actor, const char[] name );
|
||||
|
||||
/**
|
||||
* @brief Called whenever action is destroyed
|
||||
* @note You are in action destructor!
|
||||
*
|
||||
* @param action Destroyed action address
|
||||
* @param actor Actor of the action
|
||||
* @param name Name of the action
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
forward void OnActionDestroyed( BehaviorAction action, int actor, const char[] name );
|
||||
|
||||
methodmap ActionResult
|
||||
{
|
||||
/**
|
||||
* @brief Gets action result reason
|
||||
*
|
||||
* @param destination Buffer to store reason
|
||||
* @param maxlength Length of the buffer
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
public native void GetReason( char[] destination, int maxlength );
|
||||
|
||||
/**
|
||||
* @brief Sets action result reason
|
||||
*
|
||||
* @param reason String with reason
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
public native void SetReason( const char[] reason );
|
||||
|
||||
/**
|
||||
* @brief Property to get/set result type
|
||||
*
|
||||
* @return Result type (see ActionResultType)
|
||||
*/
|
||||
property ActionResultType type
|
||||
{
|
||||
public native get();
|
||||
public native set(ActionResultType type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Property to get/set result action
|
||||
*
|
||||
* @return Result action
|
||||
*/
|
||||
property BehaviorAction action
|
||||
{
|
||||
public native get();
|
||||
public native set(BehaviorAction action);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks if result is requesting change
|
||||
*
|
||||
* @return true if it is requesting, false otherwise
|
||||
*/
|
||||
public bool IsRequestingChange()
|
||||
{
|
||||
ActionResultType type = this.type;
|
||||
|
||||
return (type == CHANGE_TO || type == SUSPEND_FOR || type == DONE);
|
||||
}
|
||||
}
|
||||
|
||||
methodmap ActionDesiredResult < ActionResult
|
||||
{
|
||||
/**
|
||||
* @brief Property to get/set result priority
|
||||
*
|
||||
* @return Result priority
|
||||
*/
|
||||
property EventResultPriorityType priority
|
||||
{
|
||||
public native get();
|
||||
public native set(EventResultPriorityType priority);
|
||||
}
|
||||
}
|
||||
|
||||
typeset ActionHandler
|
||||
{
|
||||
/* OnStart, OnSuspend, OnResume */
|
||||
function Action (BehaviorAction action, int actor, BehaviorAction priorAction, ActionResult result);
|
||||
|
||||
/* OnUpdate */
|
||||
function Action (BehaviorAction action, int actor, float interval, ActionResult result);
|
||||
|
||||
/* OnEnd */
|
||||
function void (BehaviorAction action, int actor, BehaviorAction priorAction, ActionResult result);
|
||||
|
||||
/* InitialContainedAction */
|
||||
function Action (BehaviorAction action, int actor, BehaviorAction& action);
|
||||
|
||||
/* OnLeaveGround, OnLandOnGround, OnDrop, OnShoved, OnBlinded, OnHitByVomitJar, OnCommandAttack */
|
||||
function Action (BehaviorAction action, int actor, int entity, ActionDesiredResult result);
|
||||
|
||||
/* OnContact */
|
||||
function Action (BehaviorAction action, int actor, int entity, Address trace, ActionDesiredResult result);
|
||||
|
||||
/* OnMoveToSuccess */
|
||||
function Action (BehaviorAction action, int actor, Address path, ActionDesiredResult result);
|
||||
|
||||
/* OnMoveToFailure */
|
||||
function Action (BehaviorAction action, int actor, Address path, any type, ActionDesiredResult result);
|
||||
|
||||
/* OnStuck, OnUnStuck, OnPostureChanged, OnIgnite, OnModelChanged, OnEnteredSpit, OnCommandAssault, OnCommandResume */
|
||||
function Action (BehaviorAction action, int actor, ActionDesiredResult result);
|
||||
|
||||
/* OnAnimationActivityComplete, OnAnimationActivityInterrupted */
|
||||
function Action (BehaviorAction action, int actor, int activity, ActionDesiredResult result);
|
||||
|
||||
/* OnAnimationEvent */
|
||||
function Action (BehaviorAction action, int actor, Address animevent, ActionDesiredResult result);
|
||||
|
||||
/* OnInjured, OnKilled */
|
||||
function Action (BehaviorAction action, int actor, Address takedamageinfo, ActionDesiredResult result);
|
||||
|
||||
/* OnOtherKilled */
|
||||
function Action (BehaviorAction action, int actor, int other, Address takedamageinfo, ActionDesiredResult result);
|
||||
|
||||
/* OnSight, OnLostSight, OnThreatChanged */
|
||||
function Action (BehaviorAction action, int actor, int entity, ActionDesiredResult result);
|
||||
|
||||
/* OnSound */
|
||||
function Action (BehaviorAction action, int actor, int entity, const float pos[3], Address keyvalues, ActionDesiredResult result);
|
||||
|
||||
/* OnSpokeConcept */
|
||||
function Action (BehaviorAction action, int actor, int who, Address concept, Address response, Address unknown, ActionDesiredResult result);
|
||||
|
||||
/* OnNavAreaChanged */
|
||||
function Action (BehaviorAction action, int actor, Address newArea, Address oldArea, ActionDesiredResult result);
|
||||
|
||||
/* OnPickUp */
|
||||
function Action (BehaviorAction action, int actor, int entity, int giver, ActionDesiredResult result);
|
||||
|
||||
/* OnCommandApproachVector */
|
||||
function Action (BehaviorAction action, int actor, const float pos[3], float range, ActionDesiredResult result);
|
||||
|
||||
/* OnCommandApproachEntity */
|
||||
function Action (BehaviorAction action, int actor, int goal, ActionDesiredResult result);
|
||||
|
||||
/* OnCommandRetreat */
|
||||
function Action (BehaviorAction action, int actor, int threat, float range, ActionDesiredResult result);
|
||||
|
||||
/* OnCommandPause */
|
||||
function Action (BehaviorAction action, int actor, float duration, ActionDesiredResult result);
|
||||
|
||||
/* OnCommandString */
|
||||
function Action (BehaviorAction action, int actor, const char[] command, ActionDesiredResult result);
|
||||
|
||||
/* IsAbleToBlockMovementOf */
|
||||
function Action (BehaviorAction action, int actor, Address nextbot, ActionDesiredResult result);
|
||||
}
|
||||
|
||||
methodmap ActionsManager
|
||||
{
|
||||
/**
|
||||
* @brief Creates action template with given name
|
||||
* @note Use this to create your own actions
|
||||
*
|
||||
* @param name New action name
|
||||
*
|
||||
* @return Action address
|
||||
*/
|
||||
public static native BehaviorAction Create( const char[] name );
|
||||
|
||||
/**
|
||||
* @brief Allocates memory with given size
|
||||
* @note Use this with game action constructor to create game actions
|
||||
*
|
||||
* @param size Size to allocate
|
||||
*
|
||||
* @return Allocated memory start address
|
||||
*/
|
||||
public static native BehaviorAction Allocate( int size );
|
||||
|
||||
/**
|
||||
* @brief Deallocates memory
|
||||
* @note Actually used only for deallocating actions
|
||||
*
|
||||
* @param action Action to deallocate
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
public static native void Deallocate( BehaviorAction action );
|
||||
|
||||
/**
|
||||
* @brief Used to iterate over all entity actions
|
||||
*
|
||||
* @param entity Entity index
|
||||
* @param callback Iterator callback
|
||||
*
|
||||
* @return Number of actions entity has
|
||||
*/
|
||||
public static native int Iterator( int entity, ActionsIteratorCallback callback = INVALID_FUNCTION );
|
||||
|
||||
/**
|
||||
* @brief Returns entity action with given name
|
||||
*
|
||||
* @param entity Entity index
|
||||
* @param name Action name to find
|
||||
*
|
||||
* @return Action address, INVALID_ACTION if not found
|
||||
*/
|
||||
public static native BehaviorAction GetAction( int entity, const char[] name );
|
||||
}
|
||||
|
||||
methodmap BehaviorAction
|
||||
{
|
||||
public BehaviorAction(any action)
|
||||
{
|
||||
return view_as<BehaviorAction>(action);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stores pending event result
|
||||
* @note This is almost same as changing result via event handler but this one violates semantics
|
||||
*
|
||||
* @param type Result type (See ActionResultType)
|
||||
* @param action Action
|
||||
* @param priority Priority
|
||||
* @param reason Reason
|
||||
*
|
||||
* @error Invalid action passed
|
||||
* @noreturn
|
||||
*/
|
||||
public native void StorePendingEventResult( ActionResultType type = CONTINUE, BehaviorAction action = INVALID_ACTION, EventResultPriorityType priority = RESULT_TRY, const char[] reason = NULL_STRING );
|
||||
|
||||
/**
|
||||
* @brief Gets action name
|
||||
*
|
||||
* @param destination Buffer to store name
|
||||
* @param maxlength Buffer length
|
||||
*
|
||||
* @error Invalid action passed
|
||||
* @return Number of bytes written?
|
||||
*/
|
||||
public native int GetName( char[] destination, int maxlength = ACTION_NAME_LENGTH );
|
||||
|
||||
/**
|
||||
* @brief Simple wrapper to get action data
|
||||
*
|
||||
* @param int Offset to data
|
||||
* @param type How many bytes read (See NumberType)
|
||||
*
|
||||
* @return Stored data
|
||||
*/
|
||||
public any Get( int offset, NumberType type = NumberType_Int32 )
|
||||
{
|
||||
return view_as<any>(LoadFromAddress(view_as<Address>(this) + view_as<Address>(offset), type));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Simple wrapper to set action data
|
||||
*
|
||||
* @param int Offset to data
|
||||
* @param data Data to set
|
||||
* @param type How many bytes set (See NumberType)
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
#if SOURCEMOD_V_MINOR < 11
|
||||
public void Set( int offset, any data, NumberType type = NumberType_Int32 )
|
||||
{
|
||||
StoreToAddress(view_as<Address>(this) + view_as<Address>(offset), data, type);
|
||||
}
|
||||
#else
|
||||
public void Set( int offset, any data, NumberType type = NumberType_Int32, bool updateMemAccess = true )
|
||||
{
|
||||
StoreToAddress(view_as<Address>(this) + view_as<Address>(offset), data, type, updateMemAccess);
|
||||
}
|
||||
#endif
|
||||
// ====================================================================================================
|
||||
// ACTION PROPERTIES
|
||||
// ====================================================================================================
|
||||
|
||||
/**
|
||||
* @brief Property to get/set parent action
|
||||
*
|
||||
* @return Parent action
|
||||
*/
|
||||
property BehaviorAction Parent
|
||||
{
|
||||
public native get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Property to get/set child action
|
||||
*
|
||||
* @return Child action
|
||||
*/
|
||||
property BehaviorAction Child
|
||||
{
|
||||
public native get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Property to get/set "under" action
|
||||
* @note if we are suspender then this will return a suspended action
|
||||
*
|
||||
* @return Under action
|
||||
*/
|
||||
property BehaviorAction Under
|
||||
{
|
||||
public native get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Property to get/set "above" action
|
||||
* @note if we are suspended action then this will return a suspender
|
||||
*
|
||||
* @return Above action
|
||||
*/
|
||||
property BehaviorAction Above
|
||||
{
|
||||
public native get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Property to get actor of action
|
||||
* @note returns 0 if action hasn't been started yet
|
||||
*
|
||||
* @return Action actor
|
||||
*/
|
||||
property int Actor
|
||||
{
|
||||
public native get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Property to get/set suspended state of action
|
||||
*
|
||||
* @return true if suspended, false otherwise
|
||||
*/
|
||||
property bool IsSuspended
|
||||
{
|
||||
public native get();
|
||||
public native set(bool suspended);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Property to get/set started state of action
|
||||
* @note if this returns true then OnStart handled has already been called
|
||||
*
|
||||
* @return true if started, false otherwise
|
||||
*/
|
||||
property bool IsStarted
|
||||
{
|
||||
public native get();
|
||||
public native set(bool started);
|
||||
}
|
||||
|
||||
// ====================================================================================================
|
||||
// ACTION PRE EVENT HANDLERS
|
||||
// ====================================================================================================
|
||||
|
||||
property ActionHandler OnStart
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnUpdate
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnEnd
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnSuspend
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnResume
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnInitialContainedAction
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnLeaveGround
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnLandOnGround
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnContact
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnMoveToSuccess
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnMoveToFailure
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnStuck
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnUnStuck
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnPostureChanged
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnAnimationActivityComplete
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnAnimationActivityInterrupted
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnAnimationEvent
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnIgnite
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnInjured
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnKilled
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnOtherKilled
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnSight
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnLostSight
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnThreatChanged
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnSound
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnSpokeConcept
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnNavAreaChanged
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnModelChanged
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnPickUp
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnShoved
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnBlinded
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnEnteredSpit
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnHitByVomitJar
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnCommandAttack
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnCommandAssault
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnCommandApproachV
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnCommandApproachE
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnCommandRetreat
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnCommandPause
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnCommandResume
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnCommandString
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler IsAbleToBlockMovementOf
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
// ====================================================================================================
|
||||
// ACTION POST EVENT HANDLERS
|
||||
// ====================================================================================================
|
||||
|
||||
property ActionHandler OnStartPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnUpdatePost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnEndPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnSuspendPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnResumePost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnInitialContainedActionPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnLeaveGroundPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnLandOnGroundPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnContactPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnMoveToSuccessPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnMoveToFailurePost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnStuckPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnUnStuckPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnPostureChangedPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnAnimationActivityCompletePost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnAnimationActivityInterruptedPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnAnimationEventPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnIgnitePost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnInjuredPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnKilledPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnOtherKilledPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnSightPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnLostSightPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnThreatChangedPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnSoundPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnSpokeConceptPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnNavAreaChangedPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnModelChangedPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnPickUpPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnShovedPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnBlindedPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnEnteredSpitPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnHitByVomitJarPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnCommandAttackPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnCommandAssaultPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnCommandApproachVPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnCommandApproachEPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnCommandRetreatPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnCommandPausePost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnCommandResumePost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler OnCommandStringPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
|
||||
property ActionHandler IsAbleToBlockMovementOfPost
|
||||
{
|
||||
public native set(ActionHandler func);
|
||||
}
|
||||
};
|
||||
|
||||
// ====================================================================================================
|
||||
// PL NTV
|
||||
// ====================================================================================================
|
||||
|
||||
public Extension __ext_actions =
|
||||
{
|
||||
name = "Actions",
|
||||
file = "actions.ext",
|
||||
autoload = 1,
|
||||
#if defined REQUIRE_EXTENSIONS
|
||||
required = 1,
|
||||
#else
|
||||
required = 0,
|
||||
#endif
|
||||
};
|
||||
|
||||
#if !defined REQUIRE_EXTENSIONS
|
||||
public void __ext_actions_SetNTVOptional()
|
||||
{
|
||||
MarkNativeAsOptional("ActionResult.GetReason");
|
||||
MarkNativeAsOptional("ActionResult.SetReason");
|
||||
MarkNativeAsOptional("ActionResult.type.get");
|
||||
MarkNativeAsOptional("ActionResult.type.set");
|
||||
MarkNativeAsOptional("ActionResult.action.get");
|
||||
MarkNativeAsOptional("ActionResult.action.set");
|
||||
MarkNativeAsOptional("ActionDesiredResult.priority.get");
|
||||
MarkNativeAsOptional("ActionDesiredResult.priority.set");
|
||||
MarkNativeAsOptional("ActionsManager.Create");
|
||||
MarkNativeAsOptional("ActionsManager.Allocate");
|
||||
MarkNativeAsOptional("ActionsManager.Deallocate");
|
||||
MarkNativeAsOptional("ActionsManager.Iterator");
|
||||
MarkNativeAsOptional("ActionsManager.GetAction");
|
||||
MarkNativeAsOptional("BehaviorAction.StorePendingEventResult");
|
||||
MarkNativeAsOptional("BehaviorAction.GetName");
|
||||
MarkNativeAsOptional("BehaviorAction.Parent.get");
|
||||
MarkNativeAsOptional("BehaviorAction.Child.get");
|
||||
MarkNativeAsOptional("BehaviorAction.Under.get");
|
||||
MarkNativeAsOptional("BehaviorAction.Above.get");
|
||||
MarkNativeAsOptional("BehaviorAction.Actor.get");
|
||||
MarkNativeAsOptional("BehaviorAction.IsSuspended.get");
|
||||
MarkNativeAsOptional("BehaviorAction.IsSuspended.set");
|
||||
MarkNativeAsOptional("BehaviorAction.IsStarted.get");
|
||||
MarkNativeAsOptional("BehaviorAction.IsStarted.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnStart.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnUpdate.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnEnd.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnSuspend.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnResume.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnInitialContainedAction.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnLeaveGround.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnLandOnGround.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnContact.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnMoveToSuccess.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnMoveToFailure.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnStuck.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnUnStuck.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnPostureChanged.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnAnimationActivityComplete.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnAnimationActivityInterrupted.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnAnimationEvent.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnIgnite.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnInjured.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnKilled.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnOtherKilled.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnSight.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnLostSight.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnThreatChanged.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnSound.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnSpokeConcept.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnNavAreaChanged.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnModelChanged.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnPickUp.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnShoved.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnBlinded.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnEnteredSpit.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnHitByVomitJar.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnCommandAttack.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnCommandAssault.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnCommandApproachV.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnCommandApproachE.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnCommandRetreat.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnCommandPause.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnCommandResume.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnCommandString.set");
|
||||
MarkNativeAsOptional("BehaviorAction.IsAbleToBlockMovementOf.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnStartPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnUpdatePost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnEndPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnSuspendPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnResumePost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnInitialContainedActionPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnLeaveGroundPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnLandOnGroundPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnContactPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnMoveToSuccessPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnMoveToFailurePost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnStuckPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnUnStuckPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnPostureChangedPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnAnimationActivityCompletePost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnAnimationActivityInterruptedPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnAnimationEventPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnIgnitePost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnInjuredPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnKilledPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnOtherKilledPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnSightPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnLostSightPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnThreatChangedPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnSoundPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnSpokeConceptPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnNavAreaChangedPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnModelChangedPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnPickUpPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnShovedPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnBlindedPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnEnteredSpitPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnHitByVomitJarPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnCommandAttackPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnCommandAssaultPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnCommandApproachVPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnCommandApproachEPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnCommandRetreatPost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnCommandPausePost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.OnCommandResumePost.set");
|
||||
MarkNativeAsOptional("BehaviorAction.IsAbleToBlockMovementOfPost.set");
|
||||
}
|
||||
#endif
|
|
@ -1,813 +0,0 @@
|
|||
/**
|
||||
* vim: set ts=4 :
|
||||
* =============================================================================
|
||||
* sm-json
|
||||
* A pure SourcePawn JSON encoder/decoder.
|
||||
* https://github.com/clugg/sm-json
|
||||
*
|
||||
* sm-json (C)2022 James Dickens. (clug)
|
||||
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
|
||||
* =============================================================================
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 3.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* As a special exception, AlliedModders LLC gives you permission to link the
|
||||
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
||||
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
||||
* by the Valve Corporation. You must obey the GNU General Public License in
|
||||
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
||||
* this exception to all derivative works. AlliedModders LLC defines further
|
||||
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
||||
* or <http://www.sourcemod.net/license.php>.
|
||||
*/
|
||||
|
||||
#if defined _json_included
|
||||
#endinput
|
||||
#endif
|
||||
#define _json_included
|
||||
|
||||
#include <string>
|
||||
#include <json/definitions>
|
||||
#include <json/helpers/decode>
|
||||
#include <json/helpers/errors>
|
||||
#include <json/helpers/string>
|
||||
#include <json/object>
|
||||
#include <json/array>
|
||||
|
||||
/**
|
||||
* Calculates the buffer size required to store an encoded JSON instance.
|
||||
*
|
||||
* @param obj Object to encode.
|
||||
* @param options Bitwise combination of `JSON_ENCODE_*` options.
|
||||
* @param depth The current depth of the encoder.
|
||||
* @return The required buffer size.
|
||||
*/
|
||||
stock int json_encode_size(JSON_Object obj, int options = JSON_NONE, int depth = 0)
|
||||
{
|
||||
bool pretty_print = (options & JSON_ENCODE_PRETTY) != 0;
|
||||
|
||||
bool is_array = obj.IsArray;
|
||||
|
||||
int size = 1; // for opening bracket
|
||||
|
||||
// used in key iterator
|
||||
int json_size = obj.Length;
|
||||
JSON_Object child = null;
|
||||
bool is_empty = true;
|
||||
int str_length = 0;
|
||||
|
||||
int key_length = 0;
|
||||
for (int i = 0; i < json_size; i += 1) {
|
||||
key_length = is_array ? JSON_INT_BUFFER_SIZE : obj.GetKeySize(i);
|
||||
char[] key = new char[key_length];
|
||||
|
||||
if (is_array) {
|
||||
IntToString(i, key, key_length);
|
||||
} else {
|
||||
obj.GetKey(i, key, key_length);
|
||||
}
|
||||
|
||||
// skip keys that are marked as hidden
|
||||
if (obj.GetHidden(key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
JSONCellType type = obj.GetType(key);
|
||||
// skip keys of unknown type
|
||||
if (type == JSON_Type_Invalid) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pretty_print) {
|
||||
size += strlen(JSON_PP_NEWLINE);
|
||||
size += (depth + 1) * strlen(JSON_PP_INDENT);
|
||||
}
|
||||
|
||||
if (! is_array) {
|
||||
// add the size of the key and + 1 for :
|
||||
size += json_cell_string_size(key) + 1;
|
||||
|
||||
if (pretty_print) {
|
||||
size += strlen(JSON_PP_AFTER_COLON);
|
||||
}
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case JSON_Type_String: {
|
||||
str_length = obj.GetSize(key);
|
||||
char[] value = new char[str_length];
|
||||
obj.GetString(key, value, str_length);
|
||||
|
||||
size += json_cell_string_size(value);
|
||||
}
|
||||
case JSON_Type_Int: {
|
||||
size += JSON_INT_BUFFER_SIZE;
|
||||
}
|
||||
#if SM_INT64_SUPPORTED
|
||||
case JSON_Type_Int64: {
|
||||
size += JSON_INT64_BUFFER_SIZE;
|
||||
}
|
||||
#endif
|
||||
case JSON_Type_Float: {
|
||||
size += JSON_FLOAT_BUFFER_SIZE;
|
||||
}
|
||||
case JSON_Type_Bool: {
|
||||
size += JSON_BOOL_BUFFER_SIZE;
|
||||
}
|
||||
case JSON_Type_Object: {
|
||||
child = obj.GetObject(key);
|
||||
size += child != null ? json_encode_size(child, options, depth + 1) : JSON_NULL_BUFFER_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
// increment for comma
|
||||
size += 1;
|
||||
|
||||
is_empty = false;
|
||||
}
|
||||
|
||||
if (! is_empty) {
|
||||
// remove the final comma
|
||||
size -= 1;
|
||||
|
||||
if (pretty_print) {
|
||||
size += strlen(JSON_PP_NEWLINE);
|
||||
size += depth * strlen(JSON_PP_INDENT);
|
||||
}
|
||||
}
|
||||
|
||||
size += 2; // closing bracket + NULL
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes a JSON instance into its string representation.
|
||||
*
|
||||
* @param obj Object to encode.
|
||||
* @param output String buffer to store output.
|
||||
* @param max_size Maximum size of string buffer.
|
||||
* @param options Bitwise combination of `JSON_ENCODE_*` options.
|
||||
* @param depth The current depth of the encoder.
|
||||
*/
|
||||
stock void json_encode(
|
||||
JSON_Object obj,
|
||||
char[] output,
|
||||
int max_size,
|
||||
int options = JSON_NONE,
|
||||
int depth = 0
|
||||
)
|
||||
{
|
||||
bool pretty_print = (options & JSON_ENCODE_PRETTY) != 0;
|
||||
|
||||
bool is_array = obj.IsArray;
|
||||
strcopy(output, max_size, is_array ? "[" : "{");
|
||||
|
||||
// used in key iterator
|
||||
int json_size = obj.Length;
|
||||
int builder_size = 0;
|
||||
int str_length = 1;
|
||||
JSON_Object child = null;
|
||||
int cell_length = 0;
|
||||
bool is_empty = true;
|
||||
|
||||
int key_length = 0;
|
||||
for (int i = 0; i < json_size; i += 1) {
|
||||
key_length = is_array ? JSON_INT_BUFFER_SIZE : obj.GetKeySize(i);
|
||||
char[] key = new char[key_length];
|
||||
|
||||
if (is_array) {
|
||||
IntToString(i, key, key_length);
|
||||
} else {
|
||||
obj.GetKey(i, key, key_length);
|
||||
}
|
||||
|
||||
// skip keys that are marked as hidden
|
||||
if (obj.GetHidden(key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
JSONCellType type = obj.GetType(key);
|
||||
// skip keys of unknown type
|
||||
if (type == JSON_Type_Invalid) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// determine the length of the char[] needed to represent our cell data
|
||||
cell_length = 0;
|
||||
switch (type) {
|
||||
case JSON_Type_String: {
|
||||
str_length = obj.GetSize(key);
|
||||
char[] value = new char[str_length];
|
||||
obj.GetString(key, value, str_length);
|
||||
|
||||
cell_length = json_cell_string_size(value);
|
||||
}
|
||||
case JSON_Type_Int: {
|
||||
cell_length = JSON_INT_BUFFER_SIZE;
|
||||
}
|
||||
#if SM_INT64_SUPPORTED
|
||||
case JSON_Type_Int64: {
|
||||
cell_length = JSON_INT64_BUFFER_SIZE;
|
||||
}
|
||||
#endif
|
||||
case JSON_Type_Float: {
|
||||
cell_length = JSON_FLOAT_BUFFER_SIZE;
|
||||
}
|
||||
case JSON_Type_Bool: {
|
||||
cell_length = JSON_BOOL_BUFFER_SIZE;
|
||||
}
|
||||
case JSON_Type_Object: {
|
||||
child = obj.GetObject(key);
|
||||
cell_length = child != null ? max_size : JSON_NULL_BUFFER_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
// fit the contents into the cell
|
||||
char[] cell = new char[cell_length];
|
||||
switch (type) {
|
||||
case JSON_Type_String: {
|
||||
char[] value = new char[str_length];
|
||||
obj.GetString(key, value, str_length);
|
||||
json_cell_string(value, cell, cell_length);
|
||||
}
|
||||
case JSON_Type_Int: {
|
||||
int value = obj.GetInt(key);
|
||||
IntToString(value, cell, cell_length);
|
||||
}
|
||||
#if SM_INT64_SUPPORTED
|
||||
case JSON_Type_Int64: {
|
||||
int value[2];
|
||||
obj.GetInt64(key, value);
|
||||
Int64ToString(value, cell, cell_length);
|
||||
}
|
||||
#endif
|
||||
case JSON_Type_Float: {
|
||||
float value = obj.GetFloat(key);
|
||||
FloatToString(value, cell, cell_length);
|
||||
|
||||
// trim trailing 0s from float output up until decimal point
|
||||
int last_char = strlen(cell) - 1;
|
||||
while (cell[last_char] == '0' && cell[last_char - 1] != '.') {
|
||||
cell[last_char--] = '\0';
|
||||
}
|
||||
}
|
||||
case JSON_Type_Bool: {
|
||||
bool value = obj.GetBool(key);
|
||||
strcopy(cell, cell_length, value ? "true" : "false");
|
||||
}
|
||||
case JSON_Type_Object: {
|
||||
if (child != null) {
|
||||
json_encode(child, cell, cell_length, options, depth + 1);
|
||||
} else {
|
||||
strcopy(cell, cell_length, "null");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// make the builder fit our key:value
|
||||
// use previously determined cell length and + 1 for ,
|
||||
builder_size = cell_length + 1;
|
||||
if (! is_array) {
|
||||
// get the length of the key and + 1 for :
|
||||
builder_size += json_cell_string_size(key) + 1;
|
||||
|
||||
if (pretty_print) {
|
||||
builder_size += strlen(JSON_PP_AFTER_COLON);
|
||||
}
|
||||
}
|
||||
|
||||
char[] builder = new char[builder_size];
|
||||
strcopy(builder, builder_size, "");
|
||||
|
||||
// add the key if we're working with an object
|
||||
if (! is_array) {
|
||||
json_cell_string(key, builder, builder_size);
|
||||
StrCat(builder, builder_size, ":");
|
||||
|
||||
if (pretty_print) {
|
||||
StrCat(builder, builder_size, JSON_PP_AFTER_COLON);
|
||||
}
|
||||
}
|
||||
|
||||
// add the value and a trailing comma
|
||||
StrCat(builder, builder_size, cell);
|
||||
StrCat(builder, builder_size, ",");
|
||||
|
||||
// prepare pretty printing then send builder to output afterwards
|
||||
if (pretty_print) {
|
||||
StrCat(output, max_size, JSON_PP_NEWLINE);
|
||||
|
||||
for (int j = 0; j < depth + 1; j += 1) {
|
||||
StrCat(output, max_size, JSON_PP_INDENT);
|
||||
}
|
||||
}
|
||||
|
||||
StrCat(output, max_size, builder);
|
||||
|
||||
is_empty = false;
|
||||
}
|
||||
|
||||
if (! is_empty) {
|
||||
// remove the final comma
|
||||
output[strlen(output) - 1] = '\0';
|
||||
|
||||
if (pretty_print) {
|
||||
StrCat(output, max_size, JSON_PP_NEWLINE);
|
||||
|
||||
for (int j = 0; j < depth; j += 1) {
|
||||
StrCat(output, max_size, JSON_PP_INDENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// append closing bracket
|
||||
StrCat(output, max_size, is_array ? "]" : "}");
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a JSON string into a JSON instance.
|
||||
*
|
||||
* @param buffer Buffer to decode.
|
||||
* @param options Bitwise combination of `JSON_DECODE_*` options.
|
||||
* @param pos Current position of the decoder as bytes
|
||||
* offset into the buffer.
|
||||
* @param depth Current nested depth of the decoder.
|
||||
* @return JSON instance or null if decoding failed becase
|
||||
* the buffer didn't contain valid JSON.
|
||||
* @error If the buffer does not contain valid JSON,
|
||||
* an error will be thrown.
|
||||
*/
|
||||
stock JSON_Object json_decode(
|
||||
const char[] buffer,
|
||||
int options = JSON_NONE,
|
||||
int &pos = 0,
|
||||
int depth = 0
|
||||
)
|
||||
{
|
||||
int length = strlen(buffer);
|
||||
// skip preceding whitespace
|
||||
if (! json_skip_whitespace(buffer, length, pos)) {
|
||||
json_set_last_error("buffer ended early at position %d", pos);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
bool is_array = false;
|
||||
JSON_Array arr = null;
|
||||
JSON_Object obj = null;
|
||||
if (buffer[pos] == '{') {
|
||||
is_array = false;
|
||||
obj = new JSON_Object();
|
||||
} else if (buffer[pos] == '[') {
|
||||
is_array = true;
|
||||
arr = new JSON_Array();
|
||||
} else {
|
||||
json_set_last_error("no object or array found at position %d", pos);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
bool allow_single_quotes = (options & JSON_DECODE_SINGLE_QUOTES) > 0;
|
||||
|
||||
bool empty_checked = false;
|
||||
|
||||
// while we haven't reached the end of our structure
|
||||
while (
|
||||
(! is_array && buffer[pos] != '}')
|
||||
|| (is_array && buffer[pos] != ']')
|
||||
) {
|
||||
// pos is either an opening structure or comma, so increment past it
|
||||
pos += 1;
|
||||
|
||||
// skip any whitespace preceding the element
|
||||
if (! json_skip_whitespace(buffer, length, pos)) {
|
||||
json_set_last_error("buffer ended early at position %d", pos);
|
||||
json_cleanup_and_delete(obj);
|
||||
json_cleanup_and_delete(arr);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// if we haven't checked for empty yet and we are at the end
|
||||
// of an object or array, we can stop here (empty structure)
|
||||
if (! empty_checked) {
|
||||
if (
|
||||
(! is_array && buffer[pos] == '}')
|
||||
|| (is_array && buffer[pos] == ']')
|
||||
) {
|
||||
break;
|
||||
}
|
||||
|
||||
empty_checked = true;
|
||||
}
|
||||
|
||||
int key_length = 1;
|
||||
if (! is_array) {
|
||||
// if dealing with an object, look for the key and determine length
|
||||
if (! json_is_string(buffer[pos], allow_single_quotes)) {
|
||||
json_set_last_error("expected key string at position %d", pos);
|
||||
json_cleanup_and_delete(obj);
|
||||
json_cleanup_and_delete(arr);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
key_length = json_extract_string_size(
|
||||
buffer,
|
||||
length,
|
||||
pos,
|
||||
is_array
|
||||
);
|
||||
}
|
||||
|
||||
char[] key = new char[key_length];
|
||||
|
||||
if (! is_array) {
|
||||
// extract the key from the buffer
|
||||
json_extract_string(buffer, length, pos, key, key_length, is_array);
|
||||
|
||||
// skip any whitespace following the key
|
||||
if (! json_skip_whitespace(buffer, length, pos)) {
|
||||
json_set_last_error("buffer ended early at position %d", pos);
|
||||
json_cleanup_and_delete(obj);
|
||||
json_cleanup_and_delete(arr);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// ensure that we find a colon
|
||||
if (buffer[pos++] != ':') {
|
||||
json_set_last_error(
|
||||
"expected colon after key at position %d",
|
||||
pos
|
||||
);
|
||||
json_cleanup_and_delete(obj);
|
||||
json_cleanup_and_delete(arr);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// skip any whitespace following the colon
|
||||
if (! json_skip_whitespace(buffer, length, pos)) {
|
||||
json_set_last_error("buffer ended early at position %d", pos);
|
||||
json_cleanup_and_delete(obj);
|
||||
json_cleanup_and_delete(arr);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
int cell_length = 1;
|
||||
JSONCellType cell_type = JSON_Type_Invalid;
|
||||
if (buffer[pos] == '{' || buffer[pos] == '[') {
|
||||
cell_type = JSON_Type_Object;
|
||||
} else if (json_is_string(buffer[pos], allow_single_quotes)) {
|
||||
cell_type = JSON_Type_String;
|
||||
cell_length = json_extract_string_size(
|
||||
buffer,
|
||||
length,
|
||||
pos,
|
||||
is_array
|
||||
);
|
||||
} else {
|
||||
// in this particular instance, we use JSON_Type_Invalid to
|
||||
// represent any type that isn't an object or string
|
||||
cell_length = json_extract_until_end_size(
|
||||
buffer,
|
||||
length,
|
||||
pos,
|
||||
is_array
|
||||
);
|
||||
}
|
||||
|
||||
if (! is_array && obj.HasKey(key)) {
|
||||
obj.Remove(key);
|
||||
}
|
||||
|
||||
char[] cell = new char[cell_length];
|
||||
switch (cell_type) {
|
||||
case JSON_Type_Object: {
|
||||
// if we are dealing with an object or array, decode recursively
|
||||
JSON_Object value = json_decode(
|
||||
buffer,
|
||||
options,
|
||||
pos,
|
||||
depth + 1
|
||||
);
|
||||
|
||||
// decoding failed, error will be logged in json_decode
|
||||
if (value == null) {
|
||||
json_cleanup_and_delete(obj);
|
||||
json_cleanup_and_delete(arr);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_array) {
|
||||
arr.PushObject(value);
|
||||
} else {
|
||||
obj.SetObject(key, value);
|
||||
}
|
||||
}
|
||||
case JSON_Type_String: {
|
||||
// if we are dealing with a string, attempt to extract it
|
||||
if (! json_extract_string(
|
||||
buffer,
|
||||
length,
|
||||
pos,
|
||||
cell,
|
||||
cell_length,
|
||||
is_array
|
||||
)) {
|
||||
json_set_last_error(
|
||||
"couldn't extract string at position %d",
|
||||
pos
|
||||
);
|
||||
json_cleanup_and_delete(obj);
|
||||
json_cleanup_and_delete(arr);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_array) {
|
||||
arr.PushString(cell);
|
||||
} else {
|
||||
obj.SetString(key, cell);
|
||||
}
|
||||
}
|
||||
case JSON_Type_Invalid: {
|
||||
if (! json_extract_until_end(
|
||||
buffer,
|
||||
length,
|
||||
pos,
|
||||
cell,
|
||||
cell_length,
|
||||
is_array
|
||||
)) {
|
||||
json_set_last_error(
|
||||
"couldn't extract until end at position %d",
|
||||
pos
|
||||
);
|
||||
json_cleanup_and_delete(obj);
|
||||
json_cleanup_and_delete(arr);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (strlen(cell) == 0) {
|
||||
json_set_last_error(
|
||||
"empty cell encountered at position %d",
|
||||
pos
|
||||
);
|
||||
json_cleanup_and_delete(obj);
|
||||
json_cleanup_and_delete(arr);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (json_is_int(cell)) {
|
||||
int value = StringToInt(cell);
|
||||
#if SM_INT64_SUPPORTED
|
||||
if (json_is_int64(cell, value)) {
|
||||
int values[2];
|
||||
StringToInt64(cell, values);
|
||||
|
||||
if (is_array) {
|
||||
arr.PushInt64(values);
|
||||
} else {
|
||||
obj.SetInt64(key, values);
|
||||
}
|
||||
} else {
|
||||
if (is_array) {
|
||||
arr.PushInt(value);
|
||||
} else {
|
||||
obj.SetInt(key, value);
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (is_array) {
|
||||
arr.PushInt(value);
|
||||
} else {
|
||||
obj.SetInt(key, value);
|
||||
}
|
||||
#endif
|
||||
} else if (json_is_float(cell)) {
|
||||
float value = StringToFloat(cell);
|
||||
if (is_array) {
|
||||
arr.PushFloat(value);
|
||||
} else {
|
||||
obj.SetFloat(key, value);
|
||||
}
|
||||
} else if (StrEqual(cell, "true") || StrEqual(cell, "false")) {
|
||||
bool value = StrEqual(cell, "true");
|
||||
if (is_array) {
|
||||
arr.PushBool(value);
|
||||
} else {
|
||||
obj.SetBool(key, value);
|
||||
}
|
||||
} else if (StrEqual(cell, "null")) {
|
||||
if (is_array) {
|
||||
arr.PushObject(null);
|
||||
} else {
|
||||
obj.SetObject(key, null);
|
||||
}
|
||||
} else {
|
||||
json_set_last_error(
|
||||
"unknown type encountered at position %d: %s",
|
||||
pos,
|
||||
cell
|
||||
);
|
||||
json_cleanup_and_delete(obj);
|
||||
json_cleanup_and_delete(arr);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! json_skip_whitespace(buffer, length, pos)) {
|
||||
json_set_last_error("buffer ended early at position %d", pos);
|
||||
json_cleanup_and_delete(obj);
|
||||
json_cleanup_and_delete(arr);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// skip remaining whitespace and ensure we're at the end of the buffer
|
||||
pos += 1;
|
||||
if (json_skip_whitespace(buffer, length, pos) && depth == 0) {
|
||||
json_set_last_error(
|
||||
"unexpected data after structure end at position %d",
|
||||
pos
|
||||
);
|
||||
json_cleanup_and_delete(obj);
|
||||
json_cleanup_and_delete(arr);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return is_array ? view_as<JSON_Object>(arr) : obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes the object with the options provided and writes
|
||||
* the output to the file at the path specified.
|
||||
*
|
||||
* @param obj Object to encode/write to file.
|
||||
* @param path Path of file to write to.
|
||||
* @param options Options to pass to `json_encode`.
|
||||
* @return True on success, false otherwise.
|
||||
*/
|
||||
stock bool json_write_to_file(
|
||||
JSON_Object obj,
|
||||
const char[] path,
|
||||
int options = JSON_NONE
|
||||
)
|
||||
{
|
||||
File f = OpenFile(path, "wb");
|
||||
if (f == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int size = json_encode_size(obj, options);
|
||||
char[] buffer = new char[size];
|
||||
json_encode(obj, buffer, size, options);
|
||||
|
||||
bool success = f.WriteString(buffer, false);
|
||||
delete f;
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads and decodes the contents of a JSON file.
|
||||
*
|
||||
* @param path Path of file to read from.
|
||||
* @param options Options to pass to `json_decode`.
|
||||
* @return The decoded object on success, null otherwise.
|
||||
*/
|
||||
stock JSON_Object json_read_from_file(const char[] path, int options = JSON_NONE)
|
||||
{
|
||||
File f = OpenFile(path, "rb");
|
||||
if (f == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
f.Seek(0, SEEK_END);
|
||||
int size = f.Position + 1;
|
||||
char[] buffer = new char[size];
|
||||
|
||||
f.Seek(0, SEEK_SET);
|
||||
f.ReadString(buffer, size);
|
||||
delete f;
|
||||
|
||||
return json_decode(buffer, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a shallow copy of the specified object.
|
||||
*
|
||||
* @param obj Object to copy.
|
||||
* @return A shallow copy of the specified object.
|
||||
*/
|
||||
stock JSON_Object json_copy_shallow(JSON_Object obj)
|
||||
{
|
||||
bool isArray = obj.IsArray;
|
||||
JSON_Object result = isArray
|
||||
? view_as<JSON_Object>(new JSON_Array())
|
||||
: new JSON_Object();
|
||||
|
||||
if (isArray) {
|
||||
view_as<JSON_Array>(result).Concat(view_as<JSON_Array>(obj));
|
||||
} else {
|
||||
result.Merge(obj);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a deep copy of the specified object.
|
||||
*
|
||||
* @param obj Object to copy.
|
||||
* @return A deep copy of the specified object.
|
||||
*/
|
||||
stock JSON_Object json_copy_deep(JSON_Object obj)
|
||||
{
|
||||
JSON_Object result = json_copy_shallow(obj);
|
||||
|
||||
int length = obj.Length;
|
||||
int key_length = 0;
|
||||
for (int i = 0; i < length; i += 1) {
|
||||
key_length = obj.GetKeySize(i);
|
||||
char[] key = new char[key_length];
|
||||
obj.GetKey(i, key, key_length);
|
||||
|
||||
// only deep copy objects
|
||||
JSONCellType type = obj.GetType(key);
|
||||
if (type != JSON_Type_Object) {
|
||||
continue;
|
||||
}
|
||||
|
||||
JSON_Object value = obj.GetObject(key);
|
||||
result.SetObject(key, value != null ? json_copy_deep(value) : null);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively cleans up the instance and any instances stored within.
|
||||
*
|
||||
* @param obj Object to clean up.
|
||||
*/
|
||||
stock void json_cleanup(JSON_Object obj)
|
||||
{
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int length = obj.Length;
|
||||
int key_length = 0;
|
||||
for (int i = 0; i < length; i += 1) {
|
||||
key_length = obj.GetKeySize(i);
|
||||
char[] key = new char[key_length];
|
||||
obj.GetKey(i, key, key_length);
|
||||
|
||||
// only clean up objects
|
||||
JSONCellType type = obj.GetType(key);
|
||||
if (type != JSON_Type_Object) {
|
||||
continue;
|
||||
}
|
||||
|
||||
JSON_Object value = obj.GetObject(key);
|
||||
if (value != null) {
|
||||
json_cleanup(value);
|
||||
}
|
||||
}
|
||||
|
||||
obj.Super.Cleanup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up an object and sets the passed variable to null.
|
||||
*
|
||||
* @param obj Object to clean up.
|
||||
*/
|
||||
stock void json_cleanup_and_delete(JSON_Object &obj)
|
||||
{
|
||||
json_cleanup(obj);
|
||||
obj = null;
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
#if defined _info_editor_included
|
||||
#endinput
|
||||
#endif
|
||||
#define _info_editor_included
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the value of a specified key from the games mission info keyvalue system. "N/A" is returned when not found.
|
||||
*
|
||||
* @param pThis Enter the pThis value from OnGetMissionInfo/OnGetWeaponsInfo. Can specify 0 when reading Mission data.
|
||||
* @param keyname Key name to check.
|
||||
* @param dest Destination string buffer to copy to.
|
||||
* @param destLen Destination buffer length (includes null terminator).
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native void InfoEditor_GetString(int pThis, const char[] keyname, char[] dest, int destLen);
|
||||
|
||||
/**
|
||||
* Sets the value of a specified key from the games mission info keyvalue system.
|
||||
*
|
||||
* @param pThis Enter the pThis value from OnGetMissionInfo/OnGetWeaponsInfo. Can specify 0 when writing Mission data.
|
||||
* @param keyname Key name to set.
|
||||
* @param value Value to set.
|
||||
* @param create Optionally create the keyvalue if it doesn't exist.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native void InfoEditor_SetString(int pThis, const char[] keyname, const char[] value, bool create = false);
|
||||
|
||||
/**
|
||||
* Reloads the mission and weapons data configs and forces the game to reload them.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native void InfoEditor_ReloadData();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Fired multiple times when the mission info data is parsed.
|
||||
*
|
||||
* @param pThis This pointer used for InfoEditor_GetString/InfoEditor_SetString.
|
||||
*/
|
||||
forward void OnGetMissionInfo(int pThis);
|
||||
|
||||
/**
|
||||
* Fired multiple times when the weapon info data is parsed for a specific weapon classname.
|
||||
*
|
||||
* @param pThis This pointer used for InfoEditor_GetString/InfoEditor_SetString.
|
||||
* @param classname Classname of the weapon being parsed.
|
||||
*/
|
||||
forward void OnGetWeaponsInfo(int pThis, const char[] classname);
|
Loading…
Add table
Add a link
Reference in a new issue