Skip to content

Commit

Permalink
Added in basic scripting features to Dolphin
Browse files Browse the repository at this point in the history
  • Loading branch information
Lobsterzelda committed Aug 11, 2023
1 parent 0a2afa4 commit 3eaa045
Show file tree
Hide file tree
Showing 55 changed files with 4,634 additions and 0 deletions.
46 changes: 46 additions & 0 deletions Source/Core/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,50 @@ add_library(core
PowerPC/SignatureDB/MEGASignatureDB.h
PowerPC/SignatureDB/SignatureDB.cpp
PowerPC/SignatureDB/SignatureDB.h
Scripting/CoreScriptInterface/Enums/ArgTypeEnum.h
Scripting/CoreScriptInterface/Enums/GCButtonNameEnum.h
Scripting/CoreScriptInterface/Enums/ScriptCallLocationsEnum.h
Scripting/CoreScriptInterface/Enums/ScriptReturnCodesEnum.h
Scripting/CoreScriptInterface/InternalScriptAPIs/ArgHolder_APIs.h
Scripting/CoreScriptInterface/InternalScriptAPIs/ClassFunctionsResolver_APIs.h
Scripting/CoreScriptInterface/InternalScriptAPIs/ClassMetadata_APIs.h
Scripting/CoreScriptInterface/InternalScriptAPIs/FileUtility_APIs.h
Scripting/CoreScriptInterface/InternalScriptAPIs/FunctionMetadata_APIs.h
Scripting/CoreScriptInterface/InternalScriptAPIs/GCButton_APIs.h
Scripting/CoreScriptInterface/InternalScriptAPIs/ModuleLists_APIs.h
Scripting/CoreScriptInterface/InternalScriptAPIs/ScriptContext_APIs.h
Scripting/CoreScriptInterface/InternalScriptAPIs/VectorOfArgHolders_APIs.h
Scripting/HelperClasses/ArgHolder.cpp
Scripting/HelperClasses/ArgHolder.h
Scripting/HelperClasses/ArgHolder_API_Implementations.cpp
Scripting/HelperClasses/ArgHolder_API_Implementations.h
Scripting/HelperClasses/ClassFunctionsResolver_API_Implementations.cpp
Scripting/HelperClasses/ClassFunctionsResolver_API_Implementations.h
Scripting/HelperClasses/ClassMetadata.cpp
Scripting/HelperClasses/ClassMetadata.h
Scripting/HelperClasses/FileUtility_API_Implementations.cpp
Scripting/HelperClasses/FileUtility_API_Implementations.h
Scripting/HelperClasses/FunctionMetadata.cpp
Scripting/HelperClasses/FunctionMetadata.h
Scripting/HelperClasses/GCButton_API_Implementations.cpp
Scripting/HelperClasses/GCButton_API_Implementations.h
Scripting/HelperClasses/InstructionBreakpointsHolder.cpp
Scripting/HelperClasses/InstructionBreakpointsHolder.h
Scripting/HelperClasses/MemoryAddressBreakpointsHolder.cpp
Scripting/HelperClasses/MemoryAddressBreakpointsHolder.h
Scripting/HelperClasses/ModuleLists_API_Implementations.cpp
Scripting/HelperClasses/ModuleLists_API_Implementations.h
Scripting/HelperClasses/ScriptContext.cpp
Scripting/HelperClasses/ScriptContext.h
Scripting/HelperClasses/ScriptQueueEvent.h
Scripting/HelperClasses/ScriptQueueEventTypes.h
Scripting/HelperClasses/VectorOfArgHolders_API_Implementations.cpp
Scripting/HelperClasses/VectorOfArgHolders_API_Implementations.h
Scripting/HelperClasses/VersionComparisonFunctions.cpp
Scripting/HelperClasses/VersionComparisonFunctions.h
Scripting/HelperClasses/VersionResolver.h
Scripting/ScriptUtilities.cpp
Scripting/ScriptUtilities.h
State.cpp
State.h
SyncIdentifier.h
Expand Down Expand Up @@ -609,6 +653,8 @@ PUBLIC
enet::enet
expr
inputcommon
imgui
implot
MbedTLS::mbedtls
pugixml
RangeSet::RangeSet
Expand Down
23 changes: 23 additions & 0 deletions Source/Core/Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
#include "Core/PowerPC/GDBStub.h"
#include "Core/PowerPC/JitInterface.h"
#include "Core/PowerPC/PowerPC.h"
#include "Core/Scripting/ScriptUtilities.h"
#include "Core/State.h"
#include "Core/System.h"
#include "Core/WiiRoot.h"
Expand Down Expand Up @@ -904,6 +905,28 @@ void Callback_FramePresented(double actual_emulation_speed)
// Called from VideoInterface::Update (CPU thread) at emulated field boundaries
void Callback_NewField(Core::System& system)
{
// This is where script queue events are processed, where scripts are started, where frame start
// callbacks are run, where global script code is run, and where button callbacks are run (in that
// order)
if (Scripting::ScriptUtilities::IsScriptingCoreInitialized())
{
Core::QueueHostJob(
[] {
Core::RunOnCPUThread(
[] {
Scripting::ScriptUtilities::ProcessScriptQueueEvents();
if (!Scripting::ScriptUtilities::StartScripts())
{
if (!Scripting::ScriptUtilities::RunOnFrameStartCallbacks())
Scripting::ScriptUtilities::RunGlobalCode();
}
Scripting::ScriptUtilities::RunButtonCallbacksInQueues();
},
true);
},
true);
}

if (s_frame_step)
{
// To ensure that s_stop_frame_step is up to date, wait for the GPU thread queue to empty,
Expand Down
46 changes: 46 additions & 0 deletions Source/Core/Core/Scripting/CoreScriptInterface/Enums/ArgTypeEnum.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#pragma once

namespace Scripting
{

#ifdef __cplusplus
extern "C" {
#endif

// This enum represents the types of parameters for Scripting API functions, and the return types
// of Scripting API functions (which are both specified in FunctionMetadata definitions).
enum ArgTypeEnum
{
VoidType = 0,
Boolean = 1,
U8 = 2,
U16 = 3,
U32 = 4,
U64 = 5,
S8 = 6,
S16 = 7,
S32 = 8,
S64 = 9,
Float = 10,
Double = 11,
String = 12,
VoidPointer = 13,
ListOfBytes = 14,
GameCubeControllerStateObject = 15,
ListOfPoints = 16,
RegistrationInputType = 17,
RegistrationWithAutoDeregistrationInputType = 18,
RegistrationForButtonCallbackInputType = 19,
UnregistrationInputType = 20,
RegistrationReturnType = 21,
YieldType = 22,
ShutdownType = 23,
ErrorStringType = 24,
UnknownArgTypeEnum = 25
};

#ifdef __cplusplus
}
#endif

} // namespace Scripting
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#pragma once

namespace Scripting
{

#ifdef __cplusplus
extern "C" {
#endif

// GCButtonNameEnum is used to represent the names of buttons on the GameCube controller
// for various APIs that take a GameCube button as input or return a GameCube button's state.

// Each of these enums corresponds to a similarly-named variable in the Movie::ControllerState
// struct
enum GCButtonNameEnum
{
A = 0,
B = 1,
X = 2,
Y = 3,
Z = 4,
L = 5, // Refers to the digital L button (either pressed or not pressed)
R = 6, // Refers to the digital R button (either pressed or not pressed)
DPadUp = 7,
DPadDown = 8,
DPadLeft = 9,
DPadRight = 10,
AnalogStickX = 11,
AnalogStickY = 12,
CStickX = 13,
CStickY = 14,
TriggerL = 15, // Refers to the analog L trigger value (between 0-255)
TriggerR = 16, // Refers to the analog R trigger value (between 0-255)
Start = 17,
Reset = 18,
Disc = 19,
GetOrigin = 20,
IsConnected = 21,
UnknownButton = 22
};

#ifdef __cplusplus
}
#endif

} // namespace Scripting
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once

namespace Scripting
{

#ifdef __cplusplus
extern "C" {
#endif

// ScriptCallLocationsEnum represents the locations that a script can be run from.
// The ScriptUtilities file sets each script to have the appropriate enum value
// before it's run (ex. before a script's OnFrameStart callbacks are run, it has its
// script location variable set equal to FromFrameStartCallback)

// This way, a script which is running can check what context it was called from
// (which is used internally to determine if certain functions are allowed to be
// called, like OnMemoryAddressReadFrom.getMemoryAddressReadFromForCurrentCallback())
enum ScriptCallLocationsEnum
{
// When a script is run for the very first time.
FromScriptStartup = 0,

// When a script executes global code (i.e. not a registered callback function) at the
// start of a frame, and it isn't the very first time the script was run.
FromFrameStartGlobalScope = 1,

// When a registered OnFrameStart callback function is called at the start of a frame.
FromFrameStartCallback = 2,

FromInstructionHitCallback = 3,
FromMemoryAddressReadFromCallback = 4,
FromMemoryAddressWrittenToCallback = 5,
FromGCControllerInputPolledCallback = 6,
FromWiiInputPolledCallback = 7,
FromGraphicsCallback = 8,
UnknownLocation = 9
};

#ifdef __cplusplus
}
#endif

} // namespace Scripting
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once

namespace Scripting
{

#ifdef __cplusplus
extern "C" {
#endif

// ScriptReturnCodesEnum is used to represent the return value of executing a script.
// This value for a script will be SuccessCode on success, and not SuccessCode if an error occured.
enum ScriptReturnCodesEnum
{
// Indicates success (no errors occured)
SuccessCode = 0,

// Indicates that the DLL/SO file couldn't be found (or the user doesn't have permission to view
// that file)
DLLFileNotFoundError = 1,

// Indicates that the DLL/SO file didn't define a function which it was required to define
// (indicates an error for whoever wrote the DLL/SO).
DLLComponentNotFoundError = 2,

// Indicates that the script file the user tried to execute did not exist (or the user doesn't
// have permission to view that file)
ScriptFileNotFoundError = 3,

// Indicates that some kind of runtime error happened while the script was executing (usually
// indicates a bug in the script that the user wrote)
RunTimeError = 4,

UnknownError = 5
};

#ifdef __cplusplus
}
#endif

} // namespace Scripting
Loading

0 comments on commit 3eaa045

Please sign in to comment.