### Install cpu_features with DESTDIR Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/cpu_features/README.md Install the cpu_features library using DESTDIR for local repository installation, with verbose output. ```sh cmake --build build --config Release --target install -v -- DESTDIR=install ``` -------------------------------- ### Installation Directives Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/cpu_features/cmake/ci/sample/CMakeLists.txt This snippet defines how the built executable should be installed. It uses standard CMake variables for installation directories. ```cmake include(GNUInstallDirs) install(TARGETS sample EXPORT SampleTargets DESTINATION ${CMAKE_INSTALL_BIN_DIR}) ``` -------------------------------- ### Project and Include Directories Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/fmt/CMakeLists.txt Initializes the project and sets the installation directory for include files. ```cmake project(FMT CXX) include(GNUInstallDirs) set_verbose(FMT_INC_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE STRING "Installation directory for include files, a relative path that " "will be joined with ${CMAKE_INSTALL_PREFIX} or an absolute path.") ``` -------------------------------- ### Install cpu_features Library Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/cpu_features/README.md Install the cpu_features library in Release mode. Use -v for verbose output. ```sh cmake --build build --config Release --target install -v ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/CMakeLists.txt Sets the minimum required CMake version, defines the project name, and includes necessary modules. This is a foundational setup for any CMake project. ```cmake cmake_minimum_required(VERSION 3.12) cmake_policy(SET CMP0069 NEW) project(spicetools) include(CheckIPOSupported) ``` -------------------------------- ### Setup Include Directories and Definitions Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/cpu_features/CMakeLists.txt A macro to set up public and private include directories and compile definitions for a target. ```cmake macro(setup_include_and_definitions TARGET_NAME) target_include_directories(${TARGET_NAME} PUBLIC $ PRIVATE $ ) target_compile_definitions(${TARGET_NAME} PUBLIC STACK_LINE_READER_BUFFER_SIZE=1024 ) endmacro() ``` -------------------------------- ### Configure fmt Installation Paths Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/fmt/CMakeLists.txt Sets installation directories for CMake configuration files, libraries, and pkgconfig files. These paths are relative and will be joined with the installation prefix. ```cmake set_verbose(FMT_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/fmt CACHE STRING "Installation directory for cmake files, a relative path that " "will be joined with ${CMAKE_INSTALL_PREFIX} or an absolute " "path.") set(version_config ${PROJECT_BINARY_DIR}/fmt-config-version.cmake) set(project_config ${PROJECT_BINARY_DIR}/fmt-config.cmake) set(pkgconfig ${PROJECT_BINARY_DIR}/fmt.pc) set(targets_export_name fmt-targets) set_verbose(FMT_LIB_DIR ${CMAKE_INSTALL_LIBDIR} CACHE STRING "Installation directory for libraries, a relative path that " "will be joined to ${CMAKE_INSTALL_PREFIX} or an absolute path.") set_verbose(FMT_PKGCONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/pkgconfig CACHE STRING "Installation directory for pkgconfig (.pc) files, a relative " "path that will be joined with ${CMAKE_INSTALL_PREFIX} or an " "absolute path.") ``` -------------------------------- ### Install fmt Targets and Files Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/fmt/CMakeLists.txt Installs the fmt library targets, headers, and generated configuration files to their designated locations based on CMake variables. ```cmake set(INSTALL_TARGETS fmt fmt-header-only) set(INSTALL_FILE_SET) if (FMT_USE_CMAKE_MODULES) set(INSTALL_FILE_SET FILE_SET fmt DESTINATION "${FMT_INC_DIR}/fmt") endif () # Install the library and headers. install(TARGETS ${INSTALL_TARGETS} COMPONENT fmt_core EXPORT ${targets_export_name} LIBRARY DESTINATION ${FMT_LIB_DIR} ARCHIVE DESTINATION ${FMT_LIB_DIR} PUBLIC_HEADER DESTINATION "${FMT_INC_DIR}/fmt" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ${INSTALL_FILE_SET}) # Use a namespace because CMake provides better diagnostics for namespaced # imported targets. export(TARGETS ${INSTALL_TARGETS} NAMESPACE fmt:: FILE ${PROJECT_BINARY_DIR}/${targets_export_name}.cmake) # Install version, config and target files. install(FILES ${project_config} ${version_config} DESTINATION ${FMT_CMAKE_DIR} COMPONENT fmt_core) install(EXPORT ${targets_export_name} DESTINATION ${FMT_CMAKE_DIR} NAMESPACE fmt:: COMPONENT fmt_core) install(FILES "${pkgconfig}" DESTINATION "${FMT_PKGCONFIG_DIR}" COMPONENT fmt_core) ``` -------------------------------- ### Install Click for build.py Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/discord-rpc/README.md The `build.py` script depends on the `click` library. Install it using pip if you plan to use this script. ```bash pip install click ``` -------------------------------- ### Install CPU Features Library and Executable Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/cpu_features/CMakeLists.txt Installs the cpu_features library and the list_cpu_features executable, along with their associated CMake configuration files, if ENABLE_INSTALL is set. ```cmake if(ENABLE_INSTALL) include(GNUInstallDirs) install(TARGETS cpu_features EXPORT CpuFeaturesTargets PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cpu_features ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR} ) if(BUILD_EXECUTABLE) install(TARGETS list_cpu_features EXPORT CpuFeaturesTargets PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cpu_features ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR} ) endif() install(EXPORT CpuFeaturesTargets NAMESPACE CpuFeatures:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CpuFeatures COMPONENT Devel ) include(CMakePackageConfigHelpers) configure_package_config_file(cmake/CpuFeaturesConfig.cmake.in "${PROJECT_BINARY_DIR}/CpuFeaturesConfig.cmake" INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/CpuFeatures" NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO ) write_basic_package_version_file( "${PROJECT_BINARY_DIR}/CpuFeaturesConfigVersion.cmake" COMPATIBILITY SameMajorVersion ) install( FILES "${PROJECT_BINARY_DIR}/CpuFeaturesConfig.cmake" "${PROJECT_BINARY_DIR}/CpuFeaturesConfigVersion.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/CpuFeatures" COMPONENT Devel ) endif() ``` -------------------------------- ### Start Spice2x API Server Source: https://github.com/spice2x/spice2x.github.io/wiki/spice2x-features Start the API server by specifying the TCP port and an optional password. The API server launches automatically when a game starts. ```command-line spice64.exe -api 12345 -apipass "mypassword" ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/minhook/CMakeLists.txt Sets the minimum required CMake version, policy, and project name. Configures the C++ standard and warning flags for the build. ```cmake cmake_minimum_required(VERSION 3.12) cmake_policy(SET CMP0069 NEW) project(minhook) # set language level set(CMAKE_CXX_STANDARD 17) # warnings (based off SpiceTools) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") # enable stuff set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-pointer-arith") # but we love pointer arithmetic :) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas") # since CLion does clang pragmas set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-address") # to allow checking function pointers for null set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-cast-function-type") # we actually do this a lot set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-class-memaccess") # RapidJSON does this set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter") # for all those stubs set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-stringop-truncation") # since we do that from time to time set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedefs") # for our logging system # library definition set(SOURCE_FILES src/buffer.c src/hook.c src/trampoline.c src/hde/hde32.c src/hde/hde64.c) add_library(minhook STATIC ${SOURCE_FILES} dll_resources/MinHook.def) ``` -------------------------------- ### Printf Formatting Example Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/fmt/README.md Shows the concise syntax of printf for formatting floating-point numbers. ```c printf("%.2f\n", 1.23456); ``` -------------------------------- ### Check CPU Features at Runtime (x86) Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/cpu_features/README.md Example demonstrating how to check for AES and SSE4.2 instruction set support on x86 CPUs at runtime. Include 'cpuinfo_x86.h' for x86 specific features. ```c #include "cpuinfo_x86.h" // For C++, add `using namespace cpu_features;` static const X86Features features = GetX86Info().features; void Compute(void) { if (features.aes && features.sse4_2) { // Run optimized code. } else { // Run standard code. } } ``` -------------------------------- ### Build SpiceTools Project Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/README.md Execute this script to build the SpiceTools project. Ensure you have MinGW-64, bash, git, and zip installed. ```bash #!/bin/bash # Build configuration CLEAN_BUILD=1 # Set to 0 to avoid cleaning the build directory # Toolchain paths (modify if yours differ) export PATH="/usr/bin:$PATH" export PATH="/usr/x86_64-w64-mingw32/bin:$PATH" # Build the project cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release .. make -j # Create distribution package zip -r "../spice2x-$(git rev-parse --short HEAD).zip" * # Optional: UPX compression # upx --best "../spice2x-$(git rev-parse --short HEAD).zip" ``` -------------------------------- ### Experimental fmt::writer API Example Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/fmt/ChangeLog.md Demonstrates the usage of the experimental `fmt::writer` API for writing to different destinations like stdout, files, and strings. Requires including ``. ```c++ #include void write_text(fmt::writer w) { w.print("The answer is {}.", 42); } int main() { // Write to FILE. write_text(stdout); // Write to fmt::ostream. auto f = fmt::output_file("myfile"); write_text(f); // Write to std::string. auto sb = fmt::string_buffer(); write_text(sb); std::string s = sb.str(); } ``` -------------------------------- ### Iostreams Formatting Example Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/fmt/README.md Illustrates the verbosity of iostreams for formatting floating-point numbers compared to printf. ```c++ std::cout << std::setprecision(2) << std::fixed << 1.23456 << "\n"; ``` -------------------------------- ### Build Discord RPC with CMake Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/discord-rpc/README.md Use this command sequence to build the Discord RPC library. Ensure you replace placeholders with your actual paths. The `CMAKE_INSTALL_PREFIX` specifies where the library will be installed. ```bash cd mkdir build cd build cmake .. -DCMAKE_INSTALL_PREFIX= cmake --build . --config Release --target install ``` -------------------------------- ### ASIO Device Information Log Source: https://github.com/spice2x/spice2x.github.io/wiki/Audio-modes-demystified This log displays detailed information about the configured ASIO device, including channel counts, buffer sizes, and channel mapping. It is useful for verifying the ASIO backend setup. ```log I:audio::asio: Device Info: I:audio::asio: ... Name : FlexASIO I:audio::asio: ... Version : 0 I:audio::asio: ... Inputs : 0 channels I:audio::asio: ... Outputs : 2 channels I:audio::asio: ... Buffer Minimum : 48 samples I:audio::asio: ... Buffer Maximum : 48000 samples I:audio::asio: ... Buffer Preferred : 960 samples I:audio::asio: ... Buffer Granularity : 1 samples I:audio::asio: Channel Info: I:audio::asio: ... Channel 0: OUT 0 FL (Front Left) (group: 0, type: ASIOSTFloat32LSB) I:audio::asio: ... Channel 1: OUT 1 FR (Front Right) (group: 0, type: ASIOSTFloat32LSB) I:audio::asio: ASIO thread entering main loop ``` -------------------------------- ### Reject Poor Hardware Implementations (x86) Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/cpu_features/README.md Example for x86 that checks for AVX support but excludes specific microarchitectures like Sandy Bridge, which had an inefficient early implementation. Requires 'cpuinfo_x86.h' and functions to get microarchitecture details. ```c #include #include "cpuinfo_x86.h" // For C++, add `using namespace cpu_features;` static const X86Info info = GetX86Info(); static const X86Microarchitecture uarch = GetX86Microarchitecture(&info); static const bool has_fast_avx = info.features.avx && uarch != INTEL_SNB; // use has_fast_avx. ``` -------------------------------- ### Show Makefile Help Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/cpu_features/cmake/ci/README.md Run 'make' to display available targets and help information for the Makefile. ```sh make ``` -------------------------------- ### Clone and Build format-benchmark Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/fmt/README.md Clone the format-benchmark repository and configure it using CMake to prepare for running benchmarks. ```bash git clone --recursive https://github.com/fmtlib/format-benchmark.git cd format-benchmark cmake . ``` -------------------------------- ### Minimal C++ Spice SDK Entry Point Implementation Source: https://github.com/spice2x/spice2x.github.io/wiki/Spice-SDK This snippet shows the essential structure for implementing the `spice_sdk_entry_point` function in a C++ DLL hook. It includes necessary headers, initializes the SDK, checks for success, logs a message, and returns quickly. Ensure the return status from `init` is checked as the underlying executable might not support the SDK version. ```cpp #include "sdk/include/spicesdk.h" #include "sdk/include/spicesdk_io.h" SPICE_SDK_V0 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); // ask spice to fill out the function table (spice_sdk v0) status = init(0, destroy_callback, &spice_sdk); // always check the return status since the underlying executable might not implement the SDK version if (status != SPICE_SDK_STATUS_SUCCESS) { return 0; } // after this point, you can call into the functions in "spice_sdk" function table spice.log(SPICE_SDK_LOG_LEVEL_INFO, "my_hook", "plugin loaded successfully!"); // TODO: spin up a worker thread here and do work there (see C++ sample below on how to do that) // you must return quickly from this routine; this is a blocking call so the game won't boot if you stay here // return value is not checked, but it is logged return 1; } void __cdecl destroy_callback( void ) { // signal the worker thread to stop, unload } ``` -------------------------------- ### Build Unity Library Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/discord-rpc/README.md Run this command in the root directory to build the correct library files for Unity and place them in their respective folders. ```bash python build.py unity ``` -------------------------------- ### IIDX Ticker Operations Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/README.md Functions to get, set, and reset the ticker display on IIDX devices. ```APIDOC ## ticker_get() ### Description Retrieves the current text displayed on the 16-segment display. ### Method GET ### Endpoint /iidx/ticker ### Response #### Success Response (200) - **text** (string) - The text currently displayed on the ticker. ``` ```APIDOC ## ticker_set(text: str) ### Description Sets the content of the 16-segment display and disables writes from the game. ### Method POST ### Endpoint /iidx/ticker ### Parameters #### Request Body - **text** (string) - Required - The text to set on the ticker display. ``` ```APIDOC ## ticker_reset() ### Description Re-enables writes from the game to the ticker display. ### Method POST ### Endpoint /iidx/ticker/reset ``` -------------------------------- ### Set Include Directories for fmt Library Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/fmt/CMakeLists.txt Configures include directories for the fmt library, specifying build and install interfaces. ```cmake target_include_directories(fmt ${FMT_SYSTEM_HEADERS_ATTRIBUTE} BEFORE PUBLIC $ $) ``` -------------------------------- ### Set Include Directories for Header-Only Library Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/fmt/CMakeLists.txt Configures include directories for the header-only fmt library, specifying build and install interfaces. ```cmake target_include_directories(fmt-header-only ${FMT_SYSTEM_HEADERS_ATTRIBUTE} BEFORE INTERFACE $ $) ``` -------------------------------- ### Nested Specifiers in Range Formatting Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/fmt/ChangeLog.md Example demonstrating support for nested specifiers in range formatting, allowing for more complex formatting of collections. ```c++ // Example demonstrating nested specifiers in range formatting // (Specific code not provided in source, only the concept is mentioned) ``` -------------------------------- ### Finding and Linking CpuFeatures Library Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/cpu_features/cmake/ci/sample/CMakeLists.txt This snippet demonstrates how to find and link the CpuFeatures library to the executable. Ensure the CpuFeatures package is installed and discoverable by CMake. ```cmake find_package(CpuFeatures REQUIRED) add_executable(sample main.cpp) target_compile_features(sample PUBLIC cxx_std_11) set_target_properties(sample PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON VERSION ${PROJECT_VERSION}) target_link_libraries(sample PRIVATE CpuFeatures::cpu_features) ``` -------------------------------- ### Basic Enqueue and Dequeue Operations Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/readerwriterqueue/README.md Demonstrates how to use `enqueue`, `try_enqueue`, `try_dequeue`, and `peek` with the `ReaderWriterQueue`. The queue is initialized with a capacity, and operations show handling of full and empty states. ```cpp using namespace moodycamel; ReaderWriterQueue q(100); // Reserve space for at least 100 elements up front q.enqueue(17); // Will allocate memory if the queue is full bool succeeded = q.try_enqueue(18); // Will only succeed if the queue has an empty slot (never allocates) assert(succeeded); int number; succeeded = q.try_dequeue(number); // Returns false if the queue was empty assert(succeeded && number == 17); // You can also peek at the front item of the queue (consumer only) int* front = q.peek(); assert(*front == 18); succeeded = q.try_dequeue(number); assert(succeeded && number == 18); front = q.peek(); assert(front == nullptr); // Returns nullptr if the queue was empty ``` -------------------------------- ### Run CPU Features Test Executable (Shell) Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/cpu_features/README.md Demonstrates how to build and run the cpu_features library's test executable to list CPU information in a human-readable format. ```shell % ./build/list_cpu_features arch : x86 brand : Intel(R) Xeon(R) CPU E5-1650 0 @ 3.20GHz family : 6 (0x06) model : 45 (0x2D) stepping : 7 (0x07) uarch : INTEL_SNB flags : aes,avx,cx16,smx,sse4_1,sse4_2,ssse3 ``` -------------------------------- ### Build Unreal Library Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/discord-rpc/README.md Run this command in the root directory to build the correct library files for Unreal Engine and place them in their respective folders. ```bash python build.py unreal ``` -------------------------------- ### fmt::format_to Safety Improvement Example Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/fmt/ChangeLog.md Demonstrates the improved safety of `fmt::format_to` when writing to a small buffer, preventing buffer overflows by truncating output. ```cpp auto volkswagen = char[4]; auto result = fmt::format_to(volkswagen, "elephant"); ``` -------------------------------- ### Run format-benchmark Speed Test Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/fmt/README.md Execute the speed test for the format-benchmark suite after building. ```bash make speed-test ``` -------------------------------- ### Blocking Dequeue and Timed Dequeue Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/readerwriterqueue/README.md Illustrates the use of `wait_dequeue` and `wait_dequeue_timed` with `BlockingReaderWriterQueue` in a multi-threaded context. This example shows a reader and writer thread interacting with the queue. ```cpp BlockingReaderWriterQueue q; std::thread reader([&]() { int item; for (int i = 0; i != 100; ++i) { // Fully-blocking: q.wait_dequeue(item); // Blocking with timeout if (q.wait_dequeue_timed(item, std::chrono::milliseconds(5))) ++i; } }); std::thread writer([&]() { for (int i = 0; i != 100; ++i) { q.enqueue(i); std::this_thread::sleep_for(std::chrono::milliseconds(10)); } }); writer.join(); reader.join(); assert(q.size_approx() == 0); ``` -------------------------------- ### Build and Run cpu_features Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/cpu_features/README.md Build the cpu_features library in Release mode and run the list_cpu_features tool with JSON output. Use -j for parallel builds. ```sh cmake -S. -Bbuild -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=Release cmake --build build --config Release -j ./build/list_cpu_features --json ``` -------------------------------- ### Compile-time error for missing timezone info Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/fmt/ChangeLog.md Illustrates compile-time diagnostics for cases where timezone information is unavailable when formatting local time. This example will result in a compile-time error. ```c++ fmt::print("{:Z}", std::chrono::local_seconds()); ``` -------------------------------- ### SpiceTools API Response Example Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/README.md This JSON structure represents a successful response from the SpiceTools API. An empty 'errors' list indicates success, and 'data' contains the results. ```json { "id": 1, "errors": [], "data": [] } ``` -------------------------------- ### Build kbt.dll (64-bit stub) Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/CMakeLists.txt Creates a 64-bit shared library for the kbt stub. It links against fmt::fmt-header-only and defines STUB=1, using different compile flags for 64-bit architecture. ```cmake add_library(spicetools_stubs_kbt64 SHARED ${SOURCE_FILES} stubs/stubs.def) target_link_libraries(spicetools_stubs_kbt64 PRIVATE fmt::fmt-header-only) set_target_properties(spicetools_stubs_kbt64 PROPERTIES PREFIX "") set_target_properties(spicetools_stubs_kbt64 PROPERTIES OUTPUT_NAME "kbt") target_compile_definitions(spicetools_stubs_kbt64 PRIVATE STUB=1) if(NOT MSVC) set_target_properties(spicetools_stubs_kbt64 PROPERTIES COMPILE_FLAGS "-m64" LINK_FLAGS "-m64") endif() ``` -------------------------------- ### Format with custom locale for digit separators Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/fmt/ChangeLog.md Illustrates using a custom locale with a format_facet to specify UTF-8 digit separators. The example uses '’' (U+2019) as a digit separator. ```c++ auto loc = std::locale( std::locale(), new fmt::format_facet("’")); auto s = fmt::format(loc, "{:L}", 1000); ``` -------------------------------- ### Build kbt.dll (32-bit stub) Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/CMakeLists.txt Creates a 32-bit shared library for the kbt stub. It links against fmt::fmt-header-only and defines STUB=1. ```cmake set(SOURCE_FILES stubs/stubs.cpp) add_library(spicetools_stubs_kbt SHARED ${SOURCE_FILES} stubs/stubs.def) target_link_libraries(spicetools_stubs_kbt PRIVATE fmt::fmt-header-only) set_target_properties(spicetools_stubs_kbt PROPERTIES PREFIX "") set_target_properties(spicetools_stubs_kbt PROPERTIES OUTPUT_NAME "kbt") target_compile_definitions(spicetools_stubs_kbt PRIVATE STUB=1) if(NOT MSVC) set_target_properties(spicetools_stubs_kbt PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32") endif() ``` -------------------------------- ### Register k-clvsd.dll Source: https://github.com/spice2x/spice2x.github.io/wiki/DLL-Dependencies Use this command to register the k-clvsd.dll codec if it exists. Ensure the command prompt is run as administrator. ```bash regsvr32 k-clvsd.dll ``` -------------------------------- ### SpiceTools API Request Example Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/README.md This JSON structure represents a request to the SpiceTools API to insert a card into P1's reader slot. The 'id' field should match the response 'id'. ```json { "id": 1, "module": "card", "function": "insert", "params": [0, "E004010000000000"] } ``` -------------------------------- ### Register xactengine2_10.dll Source: https://github.com/spice2x/spice2x.github.io/wiki/DLL-Dependencies Use this command to register the xactengine2_10.dll codec. Ensure the command prompt is run as administrator. ```bash regsvr32 xactengine2_10.dll ``` -------------------------------- ### Benchmark Comparison: printf vs. fmt Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/fmt/ChangeLog.md Compares the compile times of different formatting methods, showing fmt 11.0.0 achieving near printf performance. ```text ------------------------------------------------------- Benchmark Time CPU Iterations ------------------------------------------------------- printf 81.8 ns 81.5 ns 8496899 fmt::print (10.x) 63.8 ns 61.9 ns 11524151 fmt::print (11.0) 51.3 ns 51.0 ns 13846580 ``` -------------------------------- ### Custom formatter for point struct using nested_formatter Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/fmt/ChangeLog.md Example of a custom formatter for a struct using fmt::nested_formatter. This allows applying formatters to subobjects with automatic width, fill, and alignment handling. ```c++ #include struct point { double x, y; }; template <> struct fmt::formatter : nested_formatter { auto format(point p, format_context& ctx) const { return write_padded(ctx, [=](auto out) { return format_to(out, "({}, {})", nested(p.x), nested(p.y)); }); } }; int main() { fmt::print("[{:>20.2f}]", point{1, 2}); } ``` -------------------------------- ### Run CPU Features Test Executable (JSON Output) Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/cpu_features/README.md Shows how to run the cpu_features library's test executable to obtain CPU information in JSON format. ```shell % ./build/list_cpu_features --json {"arch":"x86","brand":" Intel(R) Xeon(R) CPU E5-1650 0 @ 3.20GHz","family":6,"model":45,"stepping":7,"uarch":"INTEL_SNB","flags":["aes","avx","cx16","smx","sse4_1","sse4_2","ssse3"]} ``` -------------------------------- ### Compile-time format string checks Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/external/fmt/ChangeLog.md Enables compile-time checks for format string validity. This example shows how an invalid format specifier for a string type results in a compile-time error. Use `fmt::runtime` to pass runtime strings. ```c++ #include int main() { fmt::print("{:d}", "I am not a number"); } ``` ```c++ fmt::print(fmt::runtime("{:d}"), "I am not a number"); ``` -------------------------------- ### Configure spice.exe Build Source: https://github.com/spice2x/spice2x.github.io/blob/main/src/spice2x/CMakeLists.txt Sets up the build for the standard spice.exe executable on Windows. It defines resource files, links necessary libraries, and sets the output name. ```cmake set(RESOURCE_FILES build/manifest.manifest build/manifest.rc build/icon.rc cfg/Win32D.rc) add_executable(spicetools_spice ${SOURCE_FILES} ${RESOURCE_FILES}) target_link_libraries(spicetools_spice PUBLIC d3d9 ws2_32 version comctl32 shlwapi iphlpapi hid secur32 setupapi psapi winmm winhttp PRIVATE fmt::fmt-header-only discord-rpc imgui hash-library minhook imm32 dwmapi CpuFeatures::cpu_features) target_link_libraries(spicetools_spice PUBLIC winscard) set_target_properties(spicetools_spice PROPERTIES PREFIX "") set_target_properties(spicetools_spice PROPERTIES OUTPUT_NAME "spice") IF(NOT MSVC) set_target_properties(spicetools_spice PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32") endif() ```