Source SDK 2013

repository·master·Indexed 27 days ago

https://github.com/valvesoftware/source-sdk-2013

Source code for developing mods for Half-Life 2, Team Fortress 2, and HL2: Deathmatch using the Source Engine. Includes build instructions for Windows (Visual Studio 2022) and Linux (podman), guidance on distributing mods via Steam, and documentation for integrated third-party libraries such as libspng and Protocol Buffers 2.6.1. Provides API details for engine interfaces like IEngineReplay and IEngineClientReplay.

Tokens
19.9K
Snippets
51
Records
102
Agent score
94%

What's inside Source SDK 2013

  1. Understand libspng chunk semantics and error handling

    master

    Chunk data is stored within the spng_ctx.

    Error Codes

    All spng_get_*() functions return:

    • 0 on success.
    • A non-zero error code on failure.
    • SPNG_ECHUNKAVAIL if the PNG does not contain the requested chunk or it was not previously set.

    Behavior for Decoder Contexts

    • Reading Chunks: When calling spng_get_*() or spng_set_*(), all chunks up to the first IDAT are read and validated (except spng_get_ihdr(), which only reads the header). After the image is decoded, all chunks up to the IEND marker are read.
    • Setting Chunks: A successful spng_set_*() call replaces any previously set value or list. It does not combine data from the file or multiple calls.
    • Precedence: Data set via spng_set_*() is never replaced by input file chunk data; once you set a value, it persists.
  2. Install the Python Protocol Buffers runtime library

    master

    To install the Python Protocol Buffers runtime, ensure you have Python 2.4 or newer. You can verify your version using python -V. The installation process uses setup.py. Note that if you are using a Python-specific source, you must separately obtain the Protocol Compiler (protoc) from a source that includes C++ code (like the official Google package) to use the library effectively.

    Installation Steps

    1. Verify Python version: python -V
    2. Build and run tests to ensure compatibility:
      python setup.py build
      python setup.py google_test
    3. Install the library:
      python setup.py install
      (Note: This may require superuser privileges.)
    python setup.py build
    python setup.py google_test
    python setup.py install
  3. Install Protocol Buffers C++ on Unix

    master

    To build and install the C++ Protocol Buffer runtime and the protoc compiler on Unix-like systems, follow these steps. If you are using source from GitHub, you must first generate the configure script using ./autogen.sh (this downloads gtest and runs automake/autoconf). If using a release package, you can skip this step.

    Standard Build Sequence:

    1. ./configure
    2. make
    3. make check (optional, but recommended to ensure system compatibility)
    4. make install (may require superuser privileges)

    Customizing Installation Location: By default, the package installs to /usr/local. To avoid issues with LD_LIBRARY_PATH on some platforms, you can install directly to /usr using:

    ./configure --prefix=/usr

    Note: If you change the prefix, run make clean before rebuilding.

    #!/bin/bash
    ./autogen.sh
    ./configure
    make
    make check
    make install
  4. Install Java Protocol Buffers using Maven

    master

    To install the full Java Protocol Buffers runtime library into your local Maven repository, follow these steps:

    1. Install Apache Maven.
    2. Ensure the protoc executable is located in ../src and matches the version of this package (verify with protoc --version).
    3. Run tests to ensure compatibility: mvn test.
    4. Install the library: mvn install.

    If you do not use Maven for your own build management, you can generate a .jar file instead:

    mvn package

    The resulting .jar will be located in the target directory.

    mvn install
  5. Build Source SDK 2013 on Windows

    master

    To build the SDK and your mods on Windows, ensure you have Source SDK 2013 Multiplayer installed via Steam and the following development environment:

    • Visual Studio 2022 with the 'Desktop development with C++' workload, including:
      • MSVC v143 - VS 2022 C++ x64/x86 build tools (Latest)
      • Windows 11 SDK (10.0.22621.0) or Windows 10 SDK (10.0.19041.1)
    • Python 3.13 or later

    Steps to build:

    1. Clone the repository.
    2. Navigate to the src directory.
    3. Run createallprojects.bat to generate the everything.sln Visual Studio solution.
    4. Open everything.sln in Visual Studio.
    5. Select Build > Build Solution from the menu.
    6. To run your mod: Right-click the Client (Mod Name) project, select Set as Startup Project, and click the Local Windows Debugger button. The Release configuration includes default launch options.
  6. Cross-compile Protocol Buffers

    master

    When cross-compiling, the build process may attempt to execute the protoc binary it just built, which will fail if the binary is not compatible with the host machine.

    To resolve this, build a version of protoc for the host machine first, then use the --with-protoc flag during the Protocol Buffers ./configure step to point to that executable. Ensure the protoc version matches the Protocol Buffers source version.

    Example using an installed protoc:

    ./configure --with-protoc=protoc

    Example using a specific path:

    ./configure --with-protoc=../host/src/protoc
    ./configure --with-protoc=protoc
  7. Manage memory usage during decoding

    master

    To prevent excessive memory allocation when decoding potentially large or malicious PNG files, use the following methods:

    • Image Dimensions: Use spng_set_image_limits() to set hard limits on image width and height. Alternatively, call spng_decoded_image_size() to calculate the required buffer size and check it against your own limits before allocating memory.
    • Chunk Limits: Use spng_set_chunk_limits() to set hard limits on chunk length and cache size. Reaching these limits results in a fatal error.
    • Chunk Count: The SPNG_CHUNK_COUNT_LIMIT option (default 1000) controls the maximum number of chunks stored. This can be configured via spng_set_option().
  8. Enable ZLib support in Protocol Buffers

    master

    To include GzipInputStream and GzipOutputStream (google/protobuf/io/gzip_stream.h) in libprotoc, follow these steps:

    1. Obtain the zlib library (e.g., a pre-compiled DLL from zlib.net).
    2. Add the zlib headers to your include path and the .lib file to your library path.
    3. In the tests project properties, navigate to Configuration Properties > Linker > Input and add the zlib .lib file (e.g., zdll.lib) to Additional Dependencies for both Debug and Release.
    4. If building libprotobuf and libprotoc as DLLs, repeat the zlib configuration for those projects. If building as static libraries, link against zlib directly from your application.
    5. Edit config.h in the vsprojects directory and uncomment the line #define HAVE_ZLIB (or define the macro via project settings).
  9. Install Java Protocol Buffers without Maven

    master

    If you prefer not to use Maven, you can manually build the library using the protoc compiler:

    1. Ensure protoc is available and matches this package version. If you built the C++ code without installing, the binary should be in ../src.
    2. Invoke protoc to generate DescriptorProtos.java using the following command: protoc --java_out=src/main/java -I../src ../src/google/protobuf/descriptor.proto
    3. Compile the generated code in src/main/java using your preferred compiler.
    4. Install the resulting classes as needed.
    protoc --java_out=src/main/java -I../src \
             ../src/google/protobuf/descriptor.proto
  10. Perform progressive image encoding

    master

    To perform progressive encoding (useful for streaming or interlaced images), initialize the encoder by calling spng_encode_image() with the SPNG_ENCODE_PROGRESSIVE flag. In this mode, the img and len arguments are ignored.

    Non-interlaced images

    For standard images, call spng_encode_row() for each row. The loop terminates when the function returns SPNG_EOI.

    for(i = 0; i < ihdr.height; i++)
    {
        void *row = image + image_width * i;
        error = spng_encode_row(ctx, row, image_width);
        if(error) break;
    }
    if(error == SPNG_EOI) /* success */

    Interlaced images

    If spng_ihdr.interlaced_method is set to 1, rows must be accessed non-sequentially. Use spng_get_row_info() to determine the correct row number and data offset.

    do
    {
        if(spng_get_row_info(ctx, &row_info)) break;
        void *row = image + image_width * row_info.row_num;
        error = spng_encode_row(ctx, row, len);
    } while(error != SPNG_EOI);
    
    if(error == SPNG_EOI) /* success */
    // Example for non-interlaced progressive encoding
    int error;
    size_t image_width = image_size / ihdr.height;
    
    for(i = 0; i < ihdr.height; i++)
    {
        void *row = image + image_width * i;
    
        error = spng_encode_row(ctx, row, image_width);
    
        if(error) break;
    }
    
    if(error == SPNG_EOI) /* success */
  11. Perform progressive image decoding

    master

    For progressive decoding (useful for interlaced images or streaming), initialize the decoder by calling spng_decode_image() with the SPNG_DECODE_PROGRESSIVE flag.

    When this flag is set, the out and len parameters of spng_decode_image() are ignored. You must then use spng_decode_row() or spng_decode_scanline() to extract data.

    Recommended approach for all images (including interlaced): Use spng_decode_row() in a loop combined with spng_get_row_info() to ensure rows are accessed in the correct order, as interlaced images access rows non-sequentially.

    int error;
    struct spng_row_info row_info;
    
    do
    {
        error = spng_get_row_info(ctx, &row_info);
        if(error) break;
    
        void *row = image + image_width * row_info.row_num;
    
        error = spng_decode_row(ctx, row, len);
    }
    while(!error)
    
    if(error == SPNG_EOI) /* success */
  12. Install the 'Lite' version of Java Protocol Buffers with Maven

    master

    The 'lite' version of the library can be built using the Maven lite profile.

    To install the lite version into your Maven repository, use the -P lite flag. The resulting artifact will include the lite classifier, which must be specified in your dependency configuration to resolve it correctly.

    <dependency>
        <groupId>com.google.protobuf</groupId>
        <artifactId>protobuf-java</artifactId>
        <version>${version}</version>
        <classifier>lite</classifier>
    </dependency>