Page Menu
Home
Development
Search
Configure Global Search
Log In
Paste
P13
Traveler
|
AITSYS_RPC.js
Active
Public
Actions
Authored by
Lulalaby
on Apr 29 2023, 06:57.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Tags
Restricted Project
Subscribers
None
/*:
* AITSYS_RPC.js
* @plugindesc This plugin provides support for discord rpc.
*
* @author Lala Sabathil
*
* @version 4.0.0
* @filename AITSYS_RPC.js
* @url https://github.com/Aiko-IT-Systems/AITSYS.RpgMakerMv.DiscordRPC/blob/main/plugins/AITSYS_RPC.js
*
* @param --- Default Config ---
* @default
*
* @param Discord App Id
* @parent --- Default Config ---
* @type string
* @desc The discord application id bound to the rich presence
* @default 805569792446562334
*
* @param Steam App Id
* @parent --- Default Config ---
* @type string
* @desc The steam app id bound to the rich presence
* @default
*
* @param Use Button One
* @parent --- Default Config ---
* @type boolean
* @on YES
* @off NO
* @desc Do you want to display button one on the rpc?
* NO - false YES - true
* @default true
*
* @param Use Button Two
* @parent --- Default Config ---
* @type boolean
* @on YES
* @off NO
* @desc Do you want to display button two on the rpc?
* NO - false YES - true
* @default true
*
* @param --- Button One ---
* @default
*
* @param Label One
* @parent --- Button One ---
* @type string
* @desc The button label
* @default Get RPC Extension
*
* @param Url One
* @parent --- Button One ---
* @type string
* @desc The button url
* @default https://github.com/Aiko-IT-Systems/AITSYS.RpgMakerMv.Rpc
*
* @param --- Button Two ---
* @default
*
* @param Label Two
* @parent --- Button Two ---
* @type string
* @desc The button label
* @default RPC Extension Support
*
* @param Url Two
* @parent --- Button Two ---
* @type string
* @desc The button url
* @default https://discord.gg/Uk7sggRBTm
*
* @param --- Default Data ---
* @default
*
* @param Large Asset Key
* @parent --- Default Data ---
* @type string
* @desc Key for the uploaded image for the large asset or url
* @default logo
*
* @param Large Asset Text
* @parent --- Default Data ---
* @type string
* @desc Tooltip for the large asset
* @default RMMV Game
*
* @param Small Asset Key
* @parent --- Default Data ---
* @type string
* @desc Key for the uploaded image for the small asset or url
* @default
*
* @param Small Asset Text
* @parent --- Default Data ---
* @type string
* @desc Tooltip for the small asset
* @default
*
* @param Details
* @parent --- Default Data ---
* @type string
* @desc What the player is currently doing
* @default Playing Game
*
* @param State
* @parent --- Default Data ---
* @type string
* @desc The users current party status
* @default
*
* @help
*
* ============================================================================
* Introductions
* ============================================================================
*
* This plugin provides support for discord rpc.
*
* ============================================================================
* Terms of Use
* ============================================================================
*
* This plugin is free for use with credits in non-commercial and commercial
* projects as well. Editing this plugin is forbidden!
*
* Contact: Lala Sabathil (aitsys.dev) on Discord Catra#9999
*
* ============================================================================
* Change Log
* ============================================================================
*
* 2021.30.01 (v1.0.0):
* * Create first version
* 2021.31.01 (v1.1.0):
* + Added the map-changed getName Event
* 2021.18.04 (v1.3.0):
* * On null ignore
* 2022.12.10 (v2.0.0):
* + Added ignore if rpc isn't running
* 2023.14.01 (v3.0.0):
* * Reworked the plugin to control steam dlc
* 2023.XX.XX (v4.0.0):
* * Rewrote plugin for general use
*/
var
Imported
=
Imported
||
{};
Imported
.
AITSYS_RPC
=
true
;
(
function
()
{
var
AITSYS_RPC
=
AITSYS_RPC
||
{};
AITSYS_RPC
.
Version
=
"4.0.0"
;
AITSYS_RPC
.
Parameters
=
PluginManager
.
parameters
(
'AITSYS_RPC'
);
AITSYS_RPC
.
Param
=
AITSYS_RPC
.
Param
||
{};
AITSYS_RPC
.
Param
.
DiscordAppId
=
String
(
AITSYS_RPC
.
Parameters
[
'Discord App Id'
]);
AITSYS_RPC
.
Param
.
SteamAppId
=
String
(
AITSYS_RPC
.
Parameters
[
'Steam App Id'
]);
AITSYS_RPC
.
Param
.
UseButtonOne
=
Boolean
(
AITSYS_RPC
.
Parameters
[
'Use Button One'
]);
AITSYS_RPC
.
Param
.
UseButtonTwo
=
Boolean
(
AITSYS_RPC
.
Parameters
[
'Use Button Two'
]);
AITSYS_RPC
.
Param
.
LabelOne
=
String
(
AITSYS_RPC
.
Parameters
[
'Label One'
]);
AITSYS_RPC
.
Param
.
UrlOne
=
String
(
AITSYS_RPC
.
Parameters
[
'Url One'
]);
AITSYS_RPC
.
Param
.
LabelTwo
=
String
(
AITSYS_RPC
.
Parameters
[
'Label Two'
]);
AITSYS_RPC
.
Param
.
UrlTwo
=
String
(
AITSYS_RPC
.
Parameters
[
'Url Two'
]);
AITSYS_RPC
.
Param
.
LargeAssetKey
=
String
(
AITSYS_RPC
.
Parameters
[
'Large Asset Key'
]);
AITSYS_RPC
.
Param
.
LargeAssetText
=
String
(
AITSYS_RPC
.
Parameters
[
'Large Asset Text'
]);
AITSYS_RPC
.
Param
.
SmallAssetKey
=
String
(
AITSYS_RPC
.
Parameters
[
'Small Asset Key'
]);
AITSYS_RPC
.
Param
.
SmallAssetText
=
String
(
AITSYS_RPC
.
Parameters
[
'Small Asset Text'
]);
AITSYS_RPC
.
Param
.
Details
=
String
(
AITSYS_RPC
.
Parameters
[
'Details'
]);
AITSYS_RPC
.
Param
.
State
=
String
(
AITSYS_RPC
.
Parameters
[
'State'
]);
let
commandLine
=
require
(
"nw.gui"
).
App
.
argv
;
let
path
=
require
(
"path"
);
let
net
=
require
(
"net"
);
let
childProccess
=
require
(
"child_process"
);
let
child
=
null
;
const
rpcIndex
=
commandLine
.
indexOf
(
"enable-rpc"
);
chrome
.
commandLinePrivate
.
hasSwitch
(
"enable-rpc"
,
function
(
enabled
)
{
if
(
enabled
)
{
log
(
"RPC enabled (chrome param found)"
);
enableRpc
(
true
);
}
else
{
log
(
"RPC disabled (chrome param not found)"
);
}
});
if
(
rpcIndex
>
-
1
)
{
log
(
"RPC enabled (param found)"
);
enableRpc
(
true
);
}
else
{
log
(
"RPC disabled (param not found)"
);
}
function
log
(
message
)
{
console
.
info
(
message
);
}
function
setRPC
(
jsonData
)
{
log
(
"Rpc communication started."
);
log
(
"Sending: "
+
jsonData
);
var
client
=
new
net
.
Socket
();
client
.
setEncoding
(
"utf8"
);
client
.
connect
(
59090
,
"127.0.0.1"
,
function
()
{
client
.
write
(
jsonData
);
});
client
.
on
(
"data"
,
function
(
data
)
{
var
json
=
JSON
.
parse
(
data
);
if
(
json
.
type
!=
0
)
{
console
.
error
(
"Error: "
+
json
.
message
);
}
else
{
log
(
data
);
}
client
.
destroy
();
});
client
.
on
(
"close"
,
function
()
{
log
(
"Rpc communication finished"
);
});
}
function
startRpc
()
{
const
__dirname__
=
process
.
cwd
();
let
args
=
[];
if
(
AITSYS_RPC
.
Param
.
SteamAppId
!=
null
&&
AITSYS_RPC
.
Param
.
SteamAppId
!=
""
)
{
args
.
push
(
"--sapp"
);
args
.
push
(
AITSYS_RPC
.
Param
.
SteamAppId
);
}
args
.
push
(
"--dapp"
);
args
.
push
(
AITSYS_RPC
.
Param
.
DiscordAppId
);
child
=
childProccess
.
execFile
(
path
.
join
(
__dirname__
,
"/RPC Plugin"
,
"/AITSYS.RpgMakerMv.Rpc.exe"
),
args
,
(
err
,
_stdout
,
_stderr
)
=>
{
if
(
err
)
{
console
.
error
(
err
);
alert
(
err
);
return
;
}
}
);
}
function
stopRpc
()
{
if
(
child
!=
null
)
{
child
.
kill
();
}
}
enableRpc
(
false
);
window
.
callRpc
=
function
(
data
)
{
setRPC
(
data
);
};
window
.
stopRpc
=
function
()
{
stopRpc
();
};
window
.
enableRpc
=
function
(
start
=
false
)
{
enableRpc
(
start
);
};
function
enableRpc
(
start
=
true
)
{
if
(
start
)
{
startRpc
();
}
try
{
let
startupData
=
JSON
.
stringify
({
rpc_cmd
:
1
,
rpc_data
:
{
large_asset_key
:
AITSYS_RPC
.
Param
.
LargeAssetKey
,
large_asset_text
:
AITSYS_RPC
.
Param
.
LargeAssetText
,
small_asset_key
:
AITSYS_RPC
.
Param
.
SmallAssetKey
,
small_asset_text
:
AITSYS_RPC
.
Param
.
SmallAssetText
,
details
:
AITSYS_RPC
.
Param
.
Details
,
state
:
AITSYS_RPC
.
Param
.
State
,
},
});
let
startupConfig
=
JSON
.
stringify
({
rpc_cmd
:
0
,
rpc_config
:
{
use_button_one
:
AITSYS_RPC
.
Param
.
UseButtonOne
,
use_button_two
:
AITSYS_RPC
.
Param
.
UseButtonTwo
,
button_one_config
:
{
label
:
AITSYS_RPC
.
Param
.
LabelOne
,
url
:
AITSYS_RPC
.
Param
.
UrlOne
,
},
button_two_config
:
{
label
:
AITSYS_RPC
.
Param
.
LabelTwo
,
url
:
AITSYS_RPC
.
Param
.
UrlTwo
,
},
},
});
setRPC
(
startupConfig
);
setRPC
(
startupData
);
}
catch
(
e
)
{
console
.
trace
(
"Rpc communication failed"
);
}
var
gmset
=
Game_Map
.
prototype
.
setup
;
Game_Map
.
prototype
.
setup
=
function
(
mid
)
{
gmset
.
call
(
this
,
mid
);
var
currentMap
=
$dataMapInfos
[
$gameMap
.
_mapId
];
if
(
currentMap
.
name
!=
null
)
{
if
(
currentMap
.
params
.
length
!=
0
)
{
if
(
currentMap
.
params
[
0
].
type
==
"rpc"
)
{
var
data
=
currentMap
.
params
[
0
].
data
;
var
jsonData
=
JSON
.
stringify
({
rpc_cmd
:
1
,
rpc_data
:
{
large_asset_key
:
data
.
large_asset_key
??
AITSYS_RPC
.
Param
.
LargeAssetKey
,
large_asset_text
:
data
.
large_asset_text
??
AITSYS_RPC
.
Param
.
LargeAssetText
,
small_asset_key
:
data
.
small_asset_key
??
AITSYS_RPC
.
Param
.
SmallAssetKey
,
small_asset_text
:
data
.
small_asset_text
??
AITSYS_RPC
.
Param
.
SmallAssetText
,
details
:
data
.
details
,
state
:
data
.
state
,
},
});
try
{
setRPC
(
jsonData
);
}
catch
(
e
)
{
console
.
trace
(
"Rpc communication failed"
);
}
}
}
}
};
}
})();
Event Timeline
Lulalaby
created this paste.
Apr 29 2023, 06:57
2023-04-29 06:57:19 (UTC+2)
Lulalaby
created this object in space
S6 Traveler
.
Lulalaby
created this object with visibility "Public (No Login Required)".
Lulalaby
created this object with edit policy "
Lulalaby (Lala Sabathil)
".
Log In to Comment