diff --git a/Spice-SDK.md b/Spice-SDK.md index 9114e4d..f8fd135 100644 --- a/Spice-SDK.md +++ b/Spice-SDK.md @@ -1,3 +1,67 @@ -Spice SDK is a flat C, header-only library that can be included in your DLL. +Spice SDK is a flat C, header-only library that can be included in your hook DLL. Once initialized, you can call directly into helper routines provided by Spicetools executable, making low-latency and high-throughput interactions possible. + +## Instructions + +#### Include header files +Grab the latest SDK header files from the `-full` release package. Look inside `spice2x\extras\sdk\include`. + +There are currently two files - `sdkspice.h` and `spicesdk_io.h`. First one is mandatory and must be included in your project; second one is only needed if you need named enum types for buttons/analogs/lights. + +#### Add `spice_sdk_entry_point` dllexport + +See one of the `.def` files in the sample section for an example. + +#### Implement `spice_sdk_entry_point` in your project + +Sample C++ code: + +```cpp + +spice_sdk_destroy_callback_func destroy_callback; + +SPICE_SDK_ENTRY_POINT +spice_sdk_entry_point( + spice_sdk_init_func *init +) +{ + SPICE_SDK_STATUS_CODE status; + + spice.size = sizeof(spice); + status = init(0, destroy_callback, &spice); + if (status != SPICE_SDK_STATUS_SUCCESS) { + return 0; + } + + // spin up a worker thread here + return 1; +} + +void +__cdecl +destroy_callback( + void +) +{ + // unload +} + +``` + +#### Compile & run +Compile the DLL, and add to spice as a DLL hook (using `-k` parameter). + +It currently doesn't work as an early hook. + +## Sample code + +### C++ sample code +* https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/sdk/sample/v0/cpp/v0_cpp.cpp +* https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/sdk/sample/v0/cpp/v0_cpp.def + +### C Sample code + +* https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/sdk/sample/v0/flat_c/v0_flat_c.c +* https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/sdk/sample/v0/flat_c/v0_flatc.def +