เอกสาร Steamworks
ภาพรวม Steamworks API

ภาพรวม

Steamworks API จะทำให้เกมของคุณสามารถใช้งาน Steam ได้อย่างเต็มที่ ด้วยการเข้าถึงระบบพื้นฐานหลักทั้งหมดที่จัดให้ไว้ผ่านทาง API ซึ่งบรรจุเครื่องมือต่าง ๆ เช่น การหยุดเกมไว้ชั่วคราวเวลาที่ผู้ใช้เปิด โอเวอร์เลย์ Steam การเชิญเพื่อนมาร่วมเล่น การอนุญาตให้ผู้เล่นสามารถปลดล็อค รางวัลความสำเร็จ Steam การอนุญาตให้ผู้เล่นมาแข่งขันกันบน กระดานผู้นำ Steam และอื่น ๆ อีกมากมาย

ข้อมูลอ้างอิงในการใช้งาน Steamworks API ได้รวบรวมและแจกแจงรายละเอียดเกี่ยวกับอินเตอร์เฟส ฟังก์ชัน คอลแบ็ก และประเภทข้อมูลทั้งหมดที่รองรับใน API

อย่างไรก็ตาม ในการนำส่งผลิตภัณฑ์เข้าสู่ Steam ไม่จำเป็นจะต้องประสาน Steamworks API เข้าไว้ด้วย แต่ว่าทางเราขอแนะนำเป็นอย่างยิ่งว่าให้ประสานเข้าไปด้วยกัน นั่นก็เพราะว่าจะสามารถทำให้คุณสามารถใช้งานการปฏิสัมพันธ์ต่าง ๆ หลายอย่างที่ผู้ใช้ Steam คาดหวังว่าจะสามารถใช้งานได้

การเริ่มต้นใช้งาน

หมายเหตุ: Steamworks API รองรับ C++ อย่างเป็นทางการ โดยการใช้ Microsoft Visual Studio 2008+ บน Microsoft Windows, GCC 4.6+ และ Clang 3.0+ บน macOS และ SteamOS / Linux หากคุณใช้เอนจิ้นภายนอกหรือใช้ภาษาการเขียนโปรแกรมภาษาอื่นที่ไม่ใช่ C++ คุณต้องอ่านรายละเอียดที่ Commercial engine and non-C++ language support เสียก่อน เพื่อดูว่ามีคำแนะนำพิเศษเพิ่มเติมอื่น ๆ ในการเริ่มต้นใช้งานเอนจิ้นหรือภาษาการเขียนโปรแกรมที่คุณเลือกใช้หรือไม่ ในบางกรณีคุณอาจจะสามารถข้ามหลายขั้นตอนเหล่านี้ไปได้

  • หากคุณยังไม่ได้ดาวน์โหลด ให้ ดาวน์โหลด Steamworks SDK แล้วคลายซิปไฟล์
  • คัดลอกโฟลเดอร์ส่วนหัวของ Steamworks API public/steam ไปไว้ในที่ที่เหมาะสมในโครงสร้างแหล่งที่มาของแอปพลิเคชันของคุณ
  • Copy the relevant redistributable files from redistributable_bin into an appropriate place in your project folder.
    • Windows
      You must have steam_api[64].lib linking in your visual studio project. This can be linked to either the primary executable or a module that uses Steam. This allows you to access the functionality contained in steam_api[64].dll which is exposed via the Steamworks API headers. Additional Reading: Linking an Executable to a DLL (MSDN)

      You must also ship the steam_api[64].dll in your run-time directory (next to your programs executable, or in your dll search path).
    • macOS
      libsteam_api.dylib provides both the x86 and x64 version of the Steam API. You must link to this in your Xcode project and you must ship this along side your executable.
      Additional Reading: Using Dynamic Libraries
    • Linux
      libsteam_api.so You must both link to and ship this along side your executable.

การเปิดใช้งานและการปิดใช้งาน

SteamAPI_Init

หลังจากที่คุณได้ติดตั้ง Steamworks API ภายในโปรเจกต์ของตนเองแล้ว คุณจะสามารถเริ่มใช้งานโดยการเรียกคอลฟังก์ชัน SteamAPI_Init เพื่อเริ่มใช้งาน API โดยกระบวนการนี้จะดำเนินการติดตั้งสถานะส่วนกลางและรวบรวมพอยน์เตอร์ของอินเตอร์เฟสเอาไว้ด้วยกัน ซึ่งสามารถเข้าถึงได้ผ่านทางฟังก์ชันส่วนกลางที่มีชื่อตรงกันกับอินเตอร์เฟส โดยจะต้องถูกเรียกและค่าคืนให้เรียบร้อยก่อนที่จะเข้าถึง อินเตอร์เฟส Steamworks ใดๆ ก็ตาม!

หากว่า Steamworks API ไม่ทราบไอดีแอปของเกมของคุณ Steamworks API ก็จะไม่เริ่มเปิดใช้งาน เมื่อคุณเปิดใช้งานแอปของคุณจาก Steam แอปดังกล่าวจะมีไอดีแอปพร้อมให้ใช้งานโดยอัตโนมัติ ขณะที่กำลังพัฒนา คุณจำเป็นจะต้องแจ้งเรื่องนี้ให้กับ Steam ทราบด้วยไฟล์ข้อความ ให้สร้างไฟล์ข้อความที่เรียกว่า steam_appid.txt ข้าง ๆ ตัวโปรแกรมที่สั่งใช้งานได้ของคุณ ซึ่งบรรจุเพียงไอดีแอปแต่เพียงอย่างเดียวเท่านั้น โดยไม่มีอะไรอย่างอื่น กระบวนการนี้จะเแทนที่ค่าที่ Steam ได้เตรียมไว้ และคุณไม่ควรนำส่งไฟล์นี้ร่วมไปกับบิลด์ของคุณ ตัวอย่าง:
480

การคืนค่าเป็น false จะระบุหนึ่งในเงื่อนไขข้อใดข้อหนึ่งดังต่อไปนี้:
  • ไคลเอนต์ Steam ไม่ได้ทำงานอยู่ ไคลเอนต์ Steam จำเป็นต้องกำลังทำงานอยู่ เพื่อทำการตระเตรียมการใช้งานอินเตอร์เฟส ๆ ของ Steamworks
  • ไคลเอนต์ Steam ไม่สามารถระบุไอดีแอปของเกมได้ หากคุณกำลังเรียกใช้แอปพลิเคชันของคุณจากตัวโปรแกรมที่สั่งใช้งานได้หรือตัวดีบักโดยตรง คุณจะต้องมี steam_appid.txt ในไดเรกทอรีของเกมที่อยู่กับโปรแกรมที่สั่งใช้งานได้ โดยจะต้องมีไอดีแอปของคุณอยู่ในนั้น และห้ามมีอย่างอื่น Steam จะมองหาไฟล์ดังกล่าวนี้จากไดเรกทอรีปัจจุบันที่กำลังใช้งานอยู่ หากคุณกำลังเรียกใช้ตัวโปรแกรมที่สั่งใช้งานได้ของคุณจากไดเรกทอรีอื่น คุณอาจจำเป็นต้องย้ายไฟล์ steam_appid.txt
  • แอปพลิเคชันของคุณไม่ได้ทำงานภายใต้บริบทของผู้ใช้ OS เดียวกันกับไคลเอนต์ Steam เช่น ผู้ใช้ท่านอื่นหรือระดับการเข้าถึงการดูแลที่แตกต่างกัน
  • กรุณาตรวจสอบให้มั่นใจว่าคุณเป็นเจ้าของใบอนุญาตสิทธิ์ใช้งานไอดีแอปดังกล่าวบนบัญชี Steam ที่กำลังใช้งานอยู่ โดยเกมของคุณจะต้องแสดงขึ้นมาในคลัง Steam ของคุณ
  • ไอดีแอปของคุณยังไม่ได้รับการติดตั้งโดยสมบูรณ์ ซึ่งก็คือ สถานะการวางจำหน่าย: ไม่พร้อมใช้งาน หรือไม่เช่นนั้น ไอดีแอปของคุณได้ขาดแพ็กเกจเริ่มต้นไป
If you're running into initialization issues then see the การดีบัก Steamworks API documentation to learn about the various methods of debugging the Steamworks API.

SteamAPI_RestartAppIfNecessary

SteamAPI_RestartAppIfNecessary ใช้ตรวจสอบดูว่าตัวโปรแกรมที่สั่งใช้งานได้ของคุณได้ถูกเรียกใช้งานผ่านทาง Steam หรือไม่ และหากยังไม่ได้เรียกผ่านทาง Steam ก็จะเรียกใช้งานตัวโปรแกรมดังกล่าวอีกครั้งผ่านทาง Steam

วิธีนี้เป็นวิธีทางเลือก แต่ก็ขอแนะนำอย่างยิ่งว่าให้ดำเนินการ เพราะว่าบริบท Steam ที่เชื่อมโยงกับแอปพลิเคชันของคุณ (รวมถึงไอดีแอปของคุณ) จะไม่ถูกติดตั้ง หากผู้ใช้เปิดใช้งานตัวโปรแกรมที่สั่งใช้งานได้โดยตรง หากเหตุการณ์นี้เกิดขึ้น SteamAPI_Init จะล้มเหลว และคุณจะไม่สามารถใช้งาน Steamworks API ได้
หากคุณเลือกที่จะใช้งาน คุณควรจะเรียกฟังก์ชัน Steamworks ก่อนที่จะเรียก SteamAPI_Init

หากคืนเป็นค่า true กลับมา แสดงว่าได้เริ่มต้นไคลเอนต์ Steam ตามที่จำเป็นแล้ว และได้เรียกใช้งานเกมของคุณผ่านทางไคลเอนต์ Steam แล้ว และคุณควรจะต้องออกกระบวนการของคุณโดยเร็วที่สุดเท่าที่จะเป็นไปได้ ซึ่งจะทำให้เรียกใช้งาน steam://run/<AppID> อย่างมีประสิทธิภาพ ดังนั้นจึงอาจไม่จำเป็นจะต้องเปิดใช้งานตัวโปรแกรมที่สั่งใช้งานได้ตัวเดิมที่เรียกฟังก์ชันนี้แล้วซ้ำอีกครั้ง (ตัวอย่างเช่น เวลาที่คุณเรียกใช้จากตัวเครื่องมือดีบัก) เพราะต่อไปจะเปิดใช้งานโปรแกรมเวอร์ชันที่ได้ติดตั้งในโฟลเดอร์คลัง Steam ของคุณแต่เพียงอย่างเดียว

หากไม่เช่นนั้นแล้ว หากคืนค่าเป็น false กลับมา แสดงว่าเกมของคุณได้ถูกเปิดใช้งานโดยไคลเอนต์ Steam แล้ว และไม่จำเป็นต้องดำเนินการใด โดยมีข้อยกเว้น 1 ข้อ คือ หากมีไฟล์ steam_appid.txt อยู่ ก็จะคืนค่าเป็น false กลับมาเสมอ ทั้งนี้ก็เพื่อให้คุณสามารถพัฒนาและทดสอบเกม โดยไม่ต้องเปิดเกมของคุณผ่านทางไคลเอนต์ Steam ตรวจสอบให้มั่นใจว่าได้ลบไฟล์ steam_appid.txt ออก เมื่ออัปโหลดเกมของคุณไปยังดีโป Steam เรียบร้อยแล้ว!

หมายเหตุ: หากคุณใช้แรปเปอร์ DRM ของ Steam กับไฟล์ตัวโปรแกรมที่สั่งใช้งานได้ตัวหลักของคุณ ก็ไม่จำเป็นจะต้องใช้การตรวจสอบนี้เพราะว่าตัวแรปเปอร์ DRM จะดำเนินการดังกล่าวนี้ให้แล้วเป็นการภายใน

SteamAPI_Shutdown

เมื่อคุณใช้งาน Steamworks API เสร็จแล้ว คุณก็ควรจะเรียก SteamAPI_Shutdown เพื่อปล่อยทรัพยากรที่แอปพลิเคชันของคุณใช้งานเป็นการภายในอยู่ใน Steam หากเป็นไปได้ คุณควรจะเรียกคำสั่งนี้ในระหว่างการปิดใช้งานกระบวนการ

โดยคำสั่งจะเลิกจุดแทรก โอเวอร์เลย์ Steam ออกจากเกมของคุณ เนื่องจากไม่มีอะไรรับประกันว่า API การเรนเดอร์ของคุณได้ใช้งานเสร็จแล้ว

อินเตอร์เฟส Steamworks

Steamworks API ประกอบไปด้วยอินเตอร์เฟสหลายรูปแบบ ซึ่งทั้งหมดจะทำให้สามารถเข้าถึงการใช้งานต่าง ๆ เฉพาะบางส่วนได้

หลังจากที่เปิดใช้งาน Steamworks เรียบร้อยแล้ว คุณจะสามารถเข้าถึงอินเตอร์เฟสได้ผ่านทางฟังก์ชันส่วนกลางของอินเตอร์เฟสนั้น ๆ โดยฟังก์ชันจะต้องมีชื่อที่ตรงกับอินเตอร์เฟสเสมอ อย่างเช่น คุณจะสามารถเข้าถึง ISteamApps ผ่านทางตัวเข้าถึง SteamApps() และ ISteamFriends ผ่านทาง SteamFriends()

คุณสามารถใช้อินเตอร์เฟสเหล่านี้เพื่อทำการเรียก เช่น:
// Get the current users Steam name. const char *name = SteamFriends()->GetPersonaName();

คุณสามารถดูรายการอินเตอร์เฟสทั้งหมดได้ที่ ข้อมูลอ้างอิงในการใช้งาน Steamworks API หรือด้วยการไปดูในไฟล์ส่วนหัวของ Steamworks API

คอลแบ็ก

คอลแบ็กเป็นหนึ่งในวิธีการสำคัญที่สุดของ Steamworks ที่จะอนุญาตให้คุณเรียกใช้ข้อมูลแบบอสมมาตรได้จาก Steam โดยไม่จำเป็นต้องล็อกเกมของคุณ เป้าหมายของการคอลแบ็กคือ การให้กระบวนการยกระดับกิจกรรมแบบอสมมาตรที่ไม่ซับซ้อน ไม่เปลืองทรัพยากร ปลอดภัยต่อประเภทข้อมูล และปลอดภัยต่อเธรด ไว้ให้แก่ออบเจกต์ใด ๆ ก็ตามที่ได้ถูกลงทะเบียนไว้ว่าเป็นตัวเฝ้าฟังเหตุการณ์ (Listener)

โดยทั่วไปแล้วคอลแบ็กจะถูกเรียกใช้งานจากกิจกรรมที่เกิดขึ้นจาก Steam เช่น เวลาที่มีเพื่อนเข้าหรือออกจากระบบ หรือ จากผลลัพธ์แบบอสมมาตรของฟังก์ชันของ API บางฟังก์ชัน โดยคอลแบ็กแต่ละตัวประกอบไปด้วยสตรัคที่บรรจุตัวระบุเฉพาะและข้อมูลชุดเล็ก ๆ เอาไว้ คอลแบ็กจะถูกประกาศอยู่ในไฟล์ส่วนหัวของ ISteam*.h และถูกจัดรวมกลุ่มไว้กับอินเตอร์เฟสที่มีความเกี่ยวข้องด้วยมากที่สุด

ในการรับฟังการคอลแบ็ก สตรัคหรือคลาสจะต้องใช้มาโคร STEAM_CALLBACK( :classname, :functionname, :callbackname ) ที่อยู่ในคำประกาศของสตรัคหรือคลาสนั้น ๆ
  • :classname ต้องเป็นชื่อของสตรัคหรือคลาสที่คุณได้ให้นิยามไว้ (เช่น CGameManager)
  • :functionname จะเป็นชื่อของฟังก์ชันที่ได้รับการคอลแบ็กนี้ (เช่น OnGameOverlayActivated)
  • :callbackname เป็นชื่อของการคอลแบ็ก (เช่น GameOverlayActivated_t)
สิ่งนี้จะนิยามฟังก์ชันสมาชิกภายในให้แก่คลาสดังกล่าว ที่จะถูกสร้างต้นแบบเป็น void :functionname( :callbackname *pCallback ) โดยอัตโนมัติ การสร้างอินสแตนซ์ใหม่ของออบเจ็กต์จะทำให้ฟังก์ชันสมาชิกลงทะเบียนตัวเองเป็นตัวเฝ้าฟังเหตุการณ์ที่มี Steamworks API การทำลายออบเจ็กต์จะทำให้ออบเจ็กต์ปลดตัวเองออกจากทะเบียน

หมายเหตุ: คุณควรตรวจสอบให้มั่นใจว่า Steam ได้ถูกเปิดใช้งานแล้วก่อนที่จะสร้างออบเจ็กต์ที่เฝ้าฟังการคอลแบ็กต่าง ๆ

สำหรับการคอลแบ็กที่จะส่งไปให้ตัวเฝ้าฟังเหตุการณ์ที่ลงทะเบียนไว้ คุณจะต้องเรียก SteamAPI_RunCallbacks โดยแนะนำให้เรียกเป็นประจำ เนื่องจากการทิ้งเวลาระหว่างการเรียกที่นานขึ้นจะทำให้เกิดความล่าช้าระหว่างกิจกรรมที่เกิดจากการได้รับการเรียกหรือผลลัพธ์ที่ได้จาก Steamworks API โดยทั่วไปแล้วเกมส่วนมากจะเรียกคำสั่งนี้ 1 ครั้ง ต่อ 1 เฟรมเรนเดอร์ ซึ่งขอแนะนำเป็นอย่างยิ่งให้คุณเรียกอย่างน้อย 1 ครั้งต่อ 1 วินาที ฟังก์ชันตัวเฝ้าฟังเหตุการณ์ที่ลงทะเบียนไว้ทั้งหมดจะต้องถูกเรียกใช้ในระหว่างการเรียกนี้ โดยจะเรียกใช้ในบริบทเธรด SteamAPI_RunCallbacks

ตัวอย่าง

หนึ่งในคอลแบ็กที่ขอแนะนำให้คุณใช้ คือ ISteamFriends::GameOverlayActivated_t ซึ่งก็เป็นไปตามชื่อคือจะส่งคอลแบ็กให้กับคุณในทุกครั้งที่ผู้ใช้เปิดหรือปิดการใช้งาน โอเวอร์เลย์ Steam

class CGameManager { private: STEAM_CALLBACK( CGameManager, OnGameOverlayActivated, GameOverlayActivated_t ); }; void CGameManager::OnGameOverlayActivated( GameOverlayActivated_t* pCallback ) { if ( pCallback->m_bActive ) printf( "Steam overlay now active\n" ); else printf( "Steam overlay now inactive\n" ); }

หนึ่งในกรณีใช้งานที่เป็นที่นิยมและแนะนำให้ใช้กับคอลแบ็ก ISteamFriends::GameOverlayActivated_t คือ การหยุดเกมชั่วคราวเวลาที่โอเวอร์เลย์เปิดขึ้นมา

CallResults

เมธอด Steamworks หลายอย่างจะใช้ผลลัพธ์การเรียกแทนการใช้คอลแบ็ก เพื่อส่งคืนผลลัพธ์แบบอสมมาตรจากการเรียกฟังก์ชัน ความแตกต่างระหว่างการคอลแบ็กและผลลัพธ์การเรียกก็คือ การคอลแบ็กจะถูกกระจายข้อมูลไปยังตัวเฝ้าฟังเหตุการณ์ทั้งหมด ในขณะที่ผลลัพธ์การเรียกจะพุ่งเป้าหมายที่ตัวเฝ้าฟังเหตุการณ์เฉพาะเท่านั้น เช่นเดียวกันกับการคอลแบ็ก เกมของคุณจำเป็นจะต้องเรียก SteamAPI_RunCallbacks เพื่อส่งผลลัพธ์การเรียกไปยังตัวเฝ้าฟังเหตุการณ์

ซึ่งคุณจะสามารถระบุฟังก์ชันที่ให้ผลลัพธ์การเรียกได้จากการดูค่าที่ฟังก์ชันคืนค่า หากฟังก์ชันดังกล่าวคืนค่า SteamAPICall_t และมีแอตทริบิวต์ CALL_RESULT() คุณจะต้องลงทะเบียนเพื่อรับผลลัพธ์การเรียก

หมายเหตุ: การคอลแบ็กและผลลัพธ์การเรียกไม่สามารถนำมาใช้แทนที่กันได้ โดยกิจกรรมจะปรากฏออกมาผ่านอย่างใดอย่างหนึ่งเท่านั้น ไม่ปรากฏออกมาผ่านทั้งสองอย่าง คุณต้องตรวจสอบให้มั่นใจว่าคุณได้ลงทะเบียนประเภทกิจกรรมที่ถูกต้อง!

ผลลัพธ์การเรียกต้องได้รับการสร้างเป็นสมาชิกในสตรัค/คลาส โดยใช้ประเภท CCallResult และคุณยังจำเป็นจะต้องสร้างฟังก์ชันสมาชิกที่จะได้รับการคอลแบ็กดังกล่าว
void func( :callresultname *pCallback, bool bIOFailure ); CCallResult< :classname, :callresultname > m_callresultname;
  • :classname ต้องเป็นชื่อของสตรัคหรือคลาสที่คุณได้ให้นิยามไว้ (เช่น CGameManager)
  • :callresultname เป็นชื่อของการคอลแบ็ก (เช่น NumberOfCurrentPlayers_t)

คุณจะตั้งชื่อฟังก์ชัน พารามิเตอร์ของฟังก์ชัน และประเภท CCallResult เป็นชื่ออะไรก็ได้ที่คุณต้องการ

ตัวอย่าง

นี่เป็นตัวอย่างของวิธีการใช้ ISteamUserStats::GetNumberOfCurrentPlayers API ที่จะสร้างผลลัพธ์การเรียก ISteamUserStats::NumberOfCurrentPlayers_t
// In your class definition class CGameManager { public: void GetNumberOfCurrentPlayers(); private: void OnGetNumberOfCurrentPlayers( NumberOfCurrentPlayers_t *pCallback, bool bIOFailure ); CCallResult< CGameManager, NumberOfCurrentPlayers_t > m_NumberOfCurrentPlayersCallResult; }; // Make the asynchronous request to receive the number of current players. void CGameManager::GetNumberOfCurrentPlayers() { printf( "Getting Number of Current Players\n" ); SteamAPICall_t hSteamAPICall = SteamUserStats()->GetNumberOfCurrentPlayers(); m_NumberOfCurrentPlayersCallResult.Set( hSteamAPICall, this, &CGameManager::OnGetNumberOfCurrentPlayers ); } // Called when SteamUserStats()->GetNumberOfCurrentPlayers() returns asynchronously, after a call to SteamAPI_RunCallbacks(). void CGameManager::OnGetNumberOfCurrentPlayers( NumberOfCurrentPlayers_t *pCallback, bool bIOFailure ) { if ( bIOFailure || !pCallback->m_bSuccess ) { printf( "NumberOfCurrentPlayers_t failed!\n" ); return; } printf( "Number of players currently playing: %d\n", pCallback->m_cPlayers ); }

หมายเหตุ: หากคุณไม่สามารถใช้ระบบ CCallResult ได้ คุณอาจจะสามารถใช้ ISteamUtils::IsAPICallCompleted, ISteamUtils::GetAPICallResult และ ISteamUtils::GetAPICallFailureReason เพื่อติดตามสถานะของผลลัพธ์การเรียกได้

Manual Callback Dispatch

คลาสและมาโครที่ใช้เพื่อลงทะเบียนคอลแบ็กสามารถใช้งานกับโค้ด C++ ได้สะดวกง่ายดาย But there is also a lower-level mechanism for dealing with callbacks. This mechanism operates more like a windows event loop. Instead of a single function that dispatches all of the callbacks and call results to active listeners, you fetch the next available callback in a loop, and dispatch it using whatever mechanisms you want. The manual dispatch mode is especially useful for binding layers that expose the Steamworks SDK to languages other than C++. See SteamAPI_ManualDispatch_Init() in steam_api.h for more information.

Steam Game Servers

The Steamworks API includes support for running game servers as well as regular clients. A game server, in Steamworks API terms, is an entity in the system that normal users connect to to play multi-player games. This can be connecting over the Internet to a remote game server, or connecting locally to a game server that's in the same process as the client. Game servers have their own set of API functions to use, and their own unique Steam ID for other users to refer to them by.

To use the Steam Game Server API you must first include steam_gameserver.h instead of steam_api.h.

Initializing and using the game server API is very similar to the normal API:

After initializing a game server you have access to the two game server exclusive interfaces ISteamGameServer and ISteamGameServerStats.

You can also access the following regular interfaces from the game server:
  • ISteamClient ซึ่งคุณสามารถเข้าถึงได้ผ่านทางอินเตอร์เฟสส่วนกลาง: SteamGameServerClient()
  • ISteamUtils ซึ่งคุณสามารถเข้าถึงได้ผ่านทางอินเตอร์เฟสส่วนกลาง: SteamGameServerUtils()
  • ISteamNetworking ซึ่งคุณสามารถเข้าถึงได้ผ่านทางอินเตอร์เฟสส่วนกลาง: SteamGameServerNetworking()
  • ISteamHTTP ซึ่งคุณสามารถเข้าถึงได้ผ่านทางอินเตอร์เฟสส่วนกลาง: SteamGameServerHTTP()
  • ISteamUGC which you can access via the global interface: SteamGameServerUGC()
  • ISteamApps which you can access via the global interface: SteamGameServerApps()

If you're running a dedicated game server (one which has no client component), you only have to initialize the game server API's, you don't have to initialize the normal user API.

See แอปพลิเคชันตัวอย่างของ Steamworks API (SpaceWar) for a fully loaded example of using the game server API.

Unlike a game, a dedicated server will usually be run in an environment where there is no Steam Client installed to provide the latest steamworks binaries. In order for the dedicated server to have the latest steam binaries, you will need to include the Dedicated Server Redistributables with your app. Log into partner.steamgames.com and navigate to the technical settings for your app. Then look under "Installation / Redistributables" and check "Dedicated Server Redistributables"

Commercial engine and non-C++ language support

If you're using a commercial game engine or a language other than C or C++ you will want to see what level of support for the Steamworks API is provided for it.
In some engines they provide native built-in support, for others you may need a third-party solution.

If your engine does not have native support you can use the Steam Web API to access many features that Steam supports.

Regardless of how the Steamworks SDK is implemented in your engine you will need to have the latest Steamworks SDK to upload your application to Steam.

หมายเหตุ: If some of the software you are shipping on steam is available under a restrictive open source license then please see การจัดจำหน่ายแอปพลิเคชันประเภท Open Source บน Steam.

Here are some common engines that people routinely use to ship games on Steam and the relevant documentation on how to get started using the Steamworks SDK with them.

หมายเหตุ: Valve does not in any way endorse any of these engines or the third-party solutions. This list is sorted exclusively by name, and is in no way comprehensive, it exists solely as a starting guide. Engines will only be listed if they include native support or have a third-party solution that fits the guidelines. Third-party solutions will only be listed if they are kept reasonably up to date with the Steamworks SDK, are freely available under a permissive license (See: การจัดจำหน่ายแอปพลิเคชันประเภท Open Source บน Steam), and have a thread on the Steamworks Discussion Board. We recommend that you consult the community to see which option would work best for your specific setup.

เอนจิ้น:

เอนจิ้นมีการรองรับโดยพื้นฐานหรือไม่?ข้อมูล
CRYENGINE ✔️
GameMaker Studio 2 ✔️ การใช้ Steamworks SDK ร่วมกับ GameMaker: Studio
Godot Third Party: GodotSteam - Steamworks Developer Discussions support thread
Haxe ภายนอก: SteamWrap - กระทู้ฝ่ายสนับสนุนกระดานสนทนาผู้พัฒนา Steamworks
Leadwerks Game Engine ✔️ ข้อมูลอ้างอิงในการใช้งาน Leadwerks API › Steamworks
RPG Maker MV ภายนอก: Greenworks - กระทู้ฝ่ายสนับสนุนกระดานสนทนาผู้พัฒนา Steamworks
Source 2013 ✔️ Distributing Source Engine Games / Mods
Unity ภายนอก: Facepunch.Steamworks - กระทู้ฝ่ายสนับสนุนกระดานสนทนาผู้พัฒนา Steamworks
ภายนอก: http://steamworks.github.io - กระทู้ฝ่ายสนับสนุนกระดานสนทนาผู้พัฒนา Steamworks
Unreal Engine 4 ✔️ Online Subsystem Steam
Visionaire Studio ✔️ เผยแพร่บน Steam

ภาษา:

Flat interface for binding to other languages

The SDK has a few features to facilitate the creation of binding layers for other languages.

  • steam_api_flat.h declares a set of "flat" functions that mirror the interface functions in the SDK. This is not pure C code, but it does use plain C linkage and calling conventions, so it is easy to interop with other languages. These functions are exported by steam_api[64][.dll/.so/dylib].
  • steam_api.json describes (almost all of) the interfaces, types, and functions in the SDK. It is intended that this file be used by an automated process to generate binding layer. We hope that this can be used to automate 95% of the work, but there are still a few special cases that need to be handled manually. In particular, CSteamID and CGameID will probably require special handling by your binding layer to make it efficient.

Technical Details

Steam uses a variety of techniques to expose functionality to your application. It's by no means critical to understand exactly how the Steamworks API works but it's fairly simple and can be useful in planning out how to code your game with Steam integration in mind.

When you link to steam_api[64][.dll/.so/dylib] it provides access to a small number of C functions which are prefixed with the S_API macro, these functions are all exposed in steam_api.h and steam_gameserver.h. The steam_api module itself is very small, it only exposes the base functionality to initialize and shutdown the Steamworks API.

When the Steamworks API initializes it finds the actively running steam client process and loads steamclient.dll from that path. steamclient.dll is essentially the core engine of the Steam client. It contains and maintains the information necessary to run Steam. The Steam client UI uses a similar set of functions as exposed here to access the data provided by steamclient.dll. Since this data is in the Steam process, all Steam API calls are transparently marshaled and sent via an RPC/IPC mechanism. (A cross-process pipe, ISteamClient::HSteamPipe).

The Steam process, via steamclient.dll maintains a constant connection to the Steam back-end servers. Through this connection all authentication, matchmaking, friends list and VAC communication occurs. This connection may drop if the user has a network issue, or if the Steam server they are connected to receives an update. Callbacks will be posted to any running app if the connection drops or re-establishes. The Steam client will automatically try to reconnect, and clients running an app receive priority, so the typical reconnect time is under 10 seconds, although in some rare cases may be up to 5 minutes.

The Steamworks API is versioned through a COM-like mechanism, where a string name and version of an interface are passed into steamclient.dll which then returns the correct version of the interface to the caller. steamclient.dll contains a set of adapters for all released versions of an interface which redirect or re-interpret the old calls in the context of the latest interface. The adapters live inside the steam client so that they are easy to update if any issues arise.