Skip to content

Commit

Permalink
add (leaderboard)
Browse files Browse the repository at this point in the history
Chore - add build-dll
Chore - readme details
Chore - put dll file at top level of addon
Add trigger tag and result data tag
Update gitignore
  • Loading branch information
MikalDev committed Oct 18, 2023
1 parent b133655 commit f07bc57
Show file tree
Hide file tree
Showing 29 changed files with 397 additions and 72 deletions.
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,29 @@ node_modules/

/wrapper-extension/.vs

.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Local History for Visual Studio Code
.history/

# Built Visual Studio Code Extensions
*.vsix

*.tlog
*.obj
*.pch
*.ilk

*.c3addon
*.vcxproj.user
/wrapper-extension/steamworks-sdk/
/wrapper-extension/x64/
/wrapper-extension/Win32/
/construct-plugin/*.exp
/construct-plugin/*.lib
/construct-plugin/*.pdb
47 changes: 47 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"files.associations": {
"unordered_map": "cpp",
"xstring": "cpp",
"algorithm": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"cctype": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"deque": "cpp",
"exception": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"iterator": "cpp",
"limits": "cpp",
"list": "cpp",
"map": "cpp",
"memory": "cpp",
"new": "cpp",
"optional": "cpp",
"queue": "cpp",
"ranges": "cpp",
"set": "cpp",
"span": "cpp",
"string": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"utility": "cpp",
"vector": "cpp",
"xhash": "cpp",
"xmemory": "cpp",
"xtr1common": "cpp",
"xtree": "cpp",
"xutility": "cpp"
}
}
65 changes: 43 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
To build the addon, run
# About
- Open source repo for the Construct 3 Steam plus addon
- To just get the addon go to the official C3 addon site

To build the addon and dll (also see #Build below for details on other tools neede)

```
npm i
node ./build.js
npm i
npm run build // builds both addon and dll
npm run build-addon // only builds addon, uses existing dll
npm run build-dll // oly builds dll
```

To run the dev server, run
Expand All @@ -16,23 +22,11 @@ The build uses the pluginConfig file to generate everything else.

The main files you may want to look at would be instance.js and scriptInterface.js

# Scirra notes

# Read this before contributing or modifying
# Scirra notes on developing a companion addon

We are providing the source to this Construct plugin/extension for maximum flexibility for developers publishing Construct content. However this repository is not developed like a traditional open-source project, and in some cases you may be better off developing a separate "companion" plugin rather than modifying this one. Please read this guide if you plan on modifying this plugin.

## Code of conduct

This repository will be managed in accordance with Scirra's [Forum & Community guidelines](https://www.construct.net/en/forum/general/open-topic-33/forum-community-guidelines-141035).

## Accepting contributions

This plugin was authored by Scirra Ltd, the developers of Construct, which is a closed-source commercial tool. Users expect a high level of support and on-going maintenance.

While it might seem useful to submit a large amount of code to this project, we are in fact unlikely to accept large changes. This is mainly because ultimately we know will have to maintain it. We have no guarantee that the original author of a major change will be willing to maintain it, or even be contactable, especially after several years have passed. As this plugin is distributed by Scirra Ltd, responsibility defaults to us, and users will not unreasonably expect us to provide support and maintainance for it in the long-term. Supporting and maintaining large amounts of code written by other people can be extremely difficult, and over the long-term can include fully rewriting it. As a small team already managing a great deal of support and maintenance work for a commercial product, having to answer questions about, maintain, or fully rewrite a large amount of someone else's code is an outcome we specifically want to avoid. This is not a theoretical concern, as we've run in to this exact problem more than once in the past.

If you want to make major additions to this plugin, there is a better option: make a new plugin. A secondary "companion" plugin can integrate the Steamworks SDK and make API calls, but can assume the SDK is already initialized by this plugin. The companion plugin can then be developed entirely independently, and users will be aware that responsibility for maintenance of that plugin lies with someone else.
A secondary "companion" plugin can integrate the Steamworks SDK and make API calls, but can assume the SDK is already initialized by this plugin. The companion plugin can then be developed entirely independently, and users will be aware that responsibility for maintenance of that plugin lies with someone else.

For example if you want to integrate Steam Workshop features, that involes a broad set of APIs in the [ISteamUGC Interface](https://partner.steamgames.com/doc/api/ISteamUGC). If you submit a PR that adds all of those features to this plugin, we will likely reject it, since it would essentially obligate us to provide long-term commercial support for it. However you can make a new plugin that provides all those features and can be used alongside this plugin.

Expand All @@ -51,8 +45,35 @@ If you want to create a plugin that makes use of more of the Steam API, you'll w
- Add features that directly access Steam API features, skipping initialization and shutdown.
- In Construct, add both this plugin and your companion plugin to your project. This plugin will handle initialization for you and then your plugin will provide additional features.

## Making local modifications

In some cases you may want to make a modification to this plugin, but not submit your code changes. We strongly recommend making a companion plugin instead wherever feasible. However if you must, you can clone this plugin and make some changes for your own use. In that case though **you must change the plugin ID**. This essentially makes it an entirely separate kind of plugin. This will avoid severe compatibility problems and project corruption that can result if you locally modify a plugin but don't change it's ID, since your modifications will result in a plugin that Construct thinks is compatible with other projects, but is in fact incompatible.

For example if you want to make a local modification to this plugin, clone it, change the plugin ID from `Steamworks_Ext` to something like `Steamworks_Ext_MyCompanyMods`, rename it (which is only cosmetic but will help avoid confusion), and then make your modifications. Now you have your own unique plugin that you can modify to your heart's content, and won't cause compatibility nightmares with the original plugin. You should then also monitor this original codebase and merge any important changes to your cloned plugin, since they may be important updates to fix bugs or support new versions of other software. That could also prove to be significant on-going maintenance work, which is another reason a companion plugin is preferable.
## Build

To build the wrapper extension, you will need:

- [Visual Studio 2022](https://visualstudio.microsoft.com/downloads/) or newer (the *Community* edition is free)
- The [Steamworks SDK](https://partner.steamgames.com/doc/sdk) - download and extract the *sdk* subfolder in the *steamworks-sdk* subfolder such that the file `steamworks-sdk\public\steam\steam_api.h` exists.

## Add new functions
- Create new 'group' for different features (e.g. 'workshop')
- Create ACEs and functions in the group in the addon (JS) (pluginConfig.js and instance.js)
- Most ACEs will send a async message to the DLL and await a response
- In the DLL (c++) add a new function for the incoming message, make the steamworks api call, for return data or status usually add a result callback function
- Callback function can format the data as a JSON string and sent it back to the addon, there are limited data types that can be send between addon and DLL.
- In the addon (JS) On response store data in the RequestResult map as a JSON string, using the request tag trigger onRequestResult
- In events use a JSON object to parse the data and then use the data as needed. See JSON object documentation for getting data, looping, etc.

- Instead of making a new trigger and new request result condition and expression for every request, use the tag system for the condition and result
- Will add another condition for the error case

# Usage
## Requirements
- Must also include the C3 official steamworks webview 2 plug-in
## ACEs information
### Leaderboards
- See steaworks web details on leaderboards, how to create and observe a leaderboard using the steamworks web interface
- If you want to use the KeepBest method for the leaderboard, create it with the descending score option (if you change it later after you create it, it may not work)
- Uploading scores is rate limited / throttled, so if you see updates failing to take effect this may be why (learned it the hard way): https://partner.steamgames.com/doc/api/ISteamUserStats#UploadLeaderboardScore
- The result is returned as a JSON string array which can be parsed by the C3 JSON object.

# Release notes
- 1.0.0 original release
- 1.1.0 ACEs for Find Leaderboard (may change name to 'Set Current Leaderboard'), Upload Score to Leaderboard (current), Download Leaderboard, onRequestResult(tag), RequestResult(tag)
45 changes: 45 additions & 0 deletions build-dll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const { exec, execSync } = require('child_process');
const fs = require('fs');

function findMSBuildPath() {
// Common paths for various versions of Visual Studio
const potentialPaths = [
'C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/',
'C:/Program Files/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/',
'C:/Program File/Microsoft Visual Studio/2017/Community/MSBuild/15.0/Bin/',
// Add more paths as necessary
];

for (const path of potentialPaths) {
console.log('Checking ' + path);
if (fs.existsSync(path + 'MSBuild.exe')) {
console.log('Found MSBuild at ' + path);
return path + 'MSBuild.exe';
}
}

// If none of the paths work, try using the 'where' command (Windows)
try {
return execSync('where MSBuild.exe', { encoding: 'utf8', stdio: 'pipe' }).trim();
} catch (e) {
console.warn('MSBuild path not found in common directories. Please add it manually to the system PATH.');
return null;
}
}

const msbuildPath = findMSBuildPath();
const projectPath = "wrapper-extension/SteamExt.sln"

if (msbuildPath) {
exec(`"${msbuildPath}" ${projectPath} /t:Build /p:Configuration=Release`, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}

console.log(`stdout: ${stdout}`);
if (stderr) {
console.error(`stderr: ${stderr}`);
}
});
}
8 changes: 4 additions & 4 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ function getFileListFromConfig(config) {

if (config.fileDependencies) {
config.fileDependencies.forEach(function (file) {
files.push(`c3runtime/${file.filename}`);
// files.push(`c3runtime/${file.filename}`);
files.push(`${file.filename}`);
});
}

Expand Down Expand Up @@ -415,8 +416,6 @@ if (config.icon) {
}

fs.copyFileSync("./construct-plugin/Steam_x64.ext.dll", "./src/Steam_plus_x64.ext.dll");
fs.copyFileSync("./construct-plugin/Steam_x64.ext.dll", "./export/Steam_plus_x64.ext.dll");
fs.copyFileSync("./wrapper-extension/steamworks-sdk/redistributable_bin/win64/steam_api64.dll", "./src/steam_api64.dll");

function getEditorPluginInfoFromConfig(config) {
const editorPluginInfo = {
Expand Down Expand Up @@ -594,7 +593,8 @@ if (config.fileDependencies) {
config.fileDependencies.forEach((file) => {
fs.copyFileSync(
path.join(__dirname, "src", file.filename),
path.join(__dirname, "export", "c3runtime", file.filename)
path.join(__dirname, "export", file.filename)
// path.join(__dirname, "export", "c3runtime", file.filename)
);
});
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
"description": "To build the addon, run",
"version": "1.0.0",
"scripts": {
"build": "node build.js",
"build-addon": "node build.js",
"dev": "node dev.js",
"doc": "node doc.js",
"validate": "node validate.js"
"validate": "node validate.js",
"build-dll": "node build-dll.js",
"build": "node build-dll.js && node build.js"
},
"repository": {
"type": "git",
Expand Down
Binary file modified src/Steam_plus_x64.ext.dll
Binary file not shown.
3 changes: 2 additions & 1 deletion src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ SDK.Plugins[PLUGIN_INFO.id] = class extends SDK.IPluginBase {
PLUGIN_INFO.fileDependencies.forEach((file) => {
this._info.AddFileDependency({
...file,
filename: `c3runtime/${file.filename}`,
// filename: `c3runtime/${file.filename}`,
filename: `${file.filename}`,
});
});
}
Expand Down
42 changes: 40 additions & 2 deletions src/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ function getInstanceJs(parentClass, scriptInterface, addonTriggers, C3) {
// For trigger results
this._steamResult = new Map()

// trigger tag
this._triggerTag = ""

if (properties) {
}

Expand Down Expand Up @@ -77,9 +80,10 @@ function getInstanceJs(parentClass, scriptInterface, addonTriggers, C3) {
}

async _UploadLeaderboardScore(score) {
console.log('update-leaderboard-score', score)
console.log('update-leaderboard-score', score, score.toString())
const result = await this.SendWrapperExtensionMessageAsync("upload-leaderboard-score", [score]);
// Check result and respond
console.log('update-leaderboard-score result', result)
const isOk = result["isOk"];
if (isOk)
{
Expand All @@ -93,17 +97,51 @@ function getInstanceJs(parentClass, scriptInterface, addonTriggers, C3) {
}
}

_RequestData(tag) {
console.log('request-data', tag, this._steamResult)
return this._steamResult.get(tag);
}

async _DownloadLeaderboardScores(nStart, nEnd) {
const tag = "DownloadLeaderboardScores";
console.log('download-leaderboard-scores', nStart, nEnd)
const result = await this.SendWrapperExtensionMessageAsync("download-leaderboard-scores", [nStart, nEnd]);
// Check result and respond
console.log('download-leaderboard-scores result', result)
const isOk = result["isOk"];
if (isOk)
{
console.log("isOK")
this._steamResult.set(tag, result["scores"])
this._triggerTag = tag;
// Call trigger
console.log("Triggering OnRequestResult",C3 )
console.log('Plugins',C3.Plugins)
this.Trigger(C3.Plugins.cf_steamworks_plus.Cnds.OnRequestResult);
}
else
{
console.log("!isOK")
}
}

_OnRequestResult(tag) {
return this._triggerTag === tag;
}

LoadFromJson(o) {
// load state for savegames
}

/*
Trigger(method) {
super.Trigger(method);
console.log("addonTriggers", addonTriggers)
const addonTrigger = addonTriggers.find((x) => x.method === method);
if (addonTrigger) {
this.GetScriptInterface().dispatchEvent(new C3.Event(addonTrigger.id));
}
}
*/

GetScriptInterfaceClass() {
return scriptInterface;
Expand Down
1 change: 1 addition & 0 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ Object.keys(PLUGIN_INFO.Acts).forEach((key) => {
};
});
Object.keys(PLUGIN_INFO.Cnds).forEach((key) => {
console.log("key", key);
const ace = PLUGIN_INFO.Cnds[key];
P_C.Cnds[camelCasify(key)] = function (...args) {
if (ace.forward) return ace.forward(this).call(this, ...args);
Expand Down
Loading

0 comments on commit f07bc57

Please sign in to comment.