Skip to content

Commit

Permalink
Several changes
Browse files Browse the repository at this point in the history
- Add camera data to the side bar.
- Emit server data to all the clients.
- Update socket.io to the latest version.
- Add camera function to retrive the roll.
- Add roll support in the cinematic panel.
- Move the camera only when the game window is active.
- Add noggaholic icon to the window app.
- Minor bug fixes.
  • Loading branch information
karliky committed Nov 24, 2016
1 parent b6795b6 commit 1e5e531
Show file tree
Hide file tree
Showing 16 changed files with 2,070 additions and 67 deletions.
34 changes: 31 additions & 3 deletions gw2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ const Environment = require(__dirname + '/src/environment.js');
const async = require('async');
const io = require('socket.io')(8080);

let firstTime = true;
/**
* Start by trying to find the correct GW2 process
* Terminates with an error if no process is found
*/

console.log('Welcome to machinima studio! now open the ui :)');

gw2(function(err, process, module, memory, window) {
if (err) {
throw new Error(err);
}

const sendMessage = (message, data) => {
console.log(message);
socket.emit(message, data);
io.sockets.emit(message, data);
};

let socket;
Expand All @@ -34,6 +37,30 @@ gw2(function(err, process, module, memory, window) {

io.on('connection', function (so) {
socket = so;

if (firstTime) {
setInterval(() => {
let curFwd = camera.getFwdPosition();
let cameraPos = camera.getPosition();
let roll = camera.getRoll();
let data = {
x: cameraPos.x,
y: cameraPos.y,
z: cameraPos.z,
lookAtx: curFwd.x,
lookAty: curFwd.y,
lookAtz: curFwd.z,
roll: roll
};
io.sockets.emit('UPDATE_UI', data);
}, 900);
firstTime = false;
}

socket.on('error', function (err) {
console.log("Socket.IO Error");
console.log(err); // this is changed from your code in last comment
});
console.log('Window connected :)');

socket.on('RENDERING', function (data) {
Expand All @@ -49,6 +76,7 @@ gw2(function(err, process, module, memory, window) {
socket.on('CAMERA_SET_POS', function (data) {
camera.setPos(data.x, data.y, data.z);
camera.lookAt(data.lookAtx, data.lookAty, data.lookAtz);
camera.setRoll(data.roll);
if (data.timeOfDay > 0 && data.timeOfDay < 1) {
environment.setTimeOfDay(data.timeOfDay);
}
Expand Down Expand Up @@ -85,7 +113,7 @@ gw2(function(err, process, module, memory, window) {
camera.moveToWithTween(from, to, 'linear', next);
};
async.eachSeries(data, tweenTo, () => {
socket.emit('CAMERA_TWEEN_DONE');
io.sockets.emit('CAMERA_TWEEN_DONE');
});
});

Expand Down
2 changes: 1 addition & 1 deletion gw2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"dependencies": {
"md5-file": "^3.1.1",
"shifty": "^1.5.2",
"socket.io": "^1.4.8"
"socket.io": "1.6.0"
}
}
26 changes: 20 additions & 6 deletions gw2/src/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ module.exports = (process, module, memory, window, player, sendMessage) => {
const cameraWritePosition = new Buffer(0xC);
const cameraFwdWritePosition = new Buffer(0xC);

const cameraRoll = new Buffer(0x4);
const cameraRoll = new Buffer(0x4);
const cameraRollReader = new Buffer(0x4);
const cameraYaw = new Buffer(0x4);
const cameraPitch = new Buffer(0x4);
const verticalAlignment = new Buffer(0x4);
Expand Down Expand Up @@ -223,11 +224,14 @@ module.exports = (process, module, memory, window, player, sendMessage) => {
cameraRoll.writeFloatLE(0, 0x0);
let newAngle;
cameraControls = setInterval(() => {
if (robot.Window.getActive().getTitle() !== offsets.WINDOW_NAME) {
return; // only move the camera if we are inside GW2
}
let curFwd = that.getFwdPosition();
let cameraPos = that.getPosition();

let roll = that.getRoll();
if (checkForKeyStroke(robot.KEY_F3)) {
let params = { pos: cameraPos, lookAt: curFwd, timeOfDay: environment.getTimeOfDay() };
let params = { pos: cameraPos, lookAt: curFwd, timeOfDay: environment.getTimeOfDay(), roll: roll };
sendMessage('CAMERA_ADD_POSITION', params);
}

Expand Down Expand Up @@ -259,11 +263,11 @@ module.exports = (process, module, memory, window, player, sendMessage) => {
let angle = Math.atan2((curFwd.y - cameraPos.y), (curFwd.x - cameraPos.x));

if (Keyboard.getState(robot.KEY_Q)) {
cameraRoll.writeFloatLE(cameraRoll.readFloatLE(0) + 0.006, 0x0);
cameraRoll.writeFloatLE(roll + 0.006, 0x0);
}

if (Keyboard.getState(robot.KEY_E)) {
cameraRoll.writeFloatLE(cameraRoll.readFloatLE(0) - 0.006, 0x0);
cameraRoll.writeFloatLE(roll - 0.006, 0x0);
}

if (Keyboard.getState(robot.KEY_R)) {
Expand Down Expand Up @@ -349,7 +353,17 @@ module.exports = (process, module, memory, window, player, sendMessage) => {
memory.writeData(cameraOffsetBase + offsets.camera.pos.x, cameraWritePosition, 0xC);
memory.writeData(cameraOffsetBase + offsets.camera.playerPos.x, cameraFwdWritePosition, 0xC);
memory.writeData(cameraOffsetBase + offsets.camera.ortientation.roll, cameraRoll, 0x4);
}, 17);
}, 16);
};

that.setRoll = (value) => {
cameraRoll.writeFloatLE(value, 0x0);
memory.writeData(cameraOffsetBase + offsets.camera.ortientation.roll, cameraRoll, 0x4);
};

that.getRoll = () => {
memory.readData(cameraOffsetBase + offsets.camera.ortientation.roll, cameraRollReader, 0x4);
return cameraRollReader.readFloatLE(0);
};

that.getVerticalAlignment = () => {
Expand Down
2 changes: 1 addition & 1 deletion gw2/src/initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module.exports = (cb) => {

for (let w of Window.getList(offsets.WINDOW_NAME)) {
if (selectByWindow(w)) {
return cb(null, process, module, memory, window);
return cb(null, process, module, memory, w);
}
}

Expand Down
1 change: 1 addition & 0 deletions gw2ui/bottombar/css/bootstrap-multiselect.css

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

31 changes: 30 additions & 1 deletion gw2ui/bottombar/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,38 @@ body {
font-size: 11px;
}

.easingInfoParent {
margin-left:10px;
}

#subConfig {
display: inline;
}

#subConfig input {
width: 100px;
margin-right: 5px;
}

.easingInfo {
color: #8e8e8e;
text-decoration: none;
font-style: italic;
}

.easingInfo:focus {
color: #8e8e8e;
text-decoration: none;
font-style: italic;
}

.easingInfo:hover {
color: #989898;
text-decoration: none;
}
.interSelector {
color:#9d9d9d;
margin-top: 15px;
margin-top: 9px;
}

.interSelector select{
Expand Down
35 changes: 16 additions & 19 deletions gw2ui/bottombar/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title>Camera Path Editor</title>

<script>if (typeof module === 'object') {window.module = module; module = undefined;}</script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

Expand All @@ -17,6 +17,10 @@
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<link rel="stylesheet" type="text/css" href="css/style.css">

<!-- Include the plugin's multiselect CSS and JS: -->
<script type="text/javascript" src="js/bootstrap-multiselect.js"></script>
<link rel="stylesheet" href="css/bootstrap-multiselect.css" type="text/css"/>
</head>
<body>
<nav class="navbar navbar-inverse">
Expand Down Expand Up @@ -54,28 +58,21 @@
<li>
<div class="interSelector">
<span class="glyphicon glyphicon-send"></span> Interpolation
<select>
<option selected="selected">Power0</option>
<option>Power1</option>
<option>Power2</option>
<option>Power3</option>
<option>Power4</option>
<option>Back</option>
<option>Elastic</option>
<option>Bounce</option>
<option>Rough</option>
<option>SlowMo</option>
<option>Stepped</option>
<option>Circ</option>
<option>Expo</option>
<option>Sine</option>
<select id="easeBase">
</select>
<select id="easeSub">
</select>
<div id="subConfig">
</div>
</div>
</li>
<li>
<div class="durationSelector">
<span class="glyphicon glyphicon-time"></span> Duration
<input type="text" value="8"/> seconds
<span class="easingInfoParent">
<a href="http://greensock.com/ease-visualizer" class="easingInfo" target="_blank"> <span class="glyphicon glyphicon-info-sign"></span> Open ease visualizer</a>
</span>
</div>
</li>
</ul>
Expand All @@ -92,7 +89,7 @@
<th>lookat x</th>
<th>lookat y</th>
<th>lookat z</th>
<th>Field Of view</th>
<th>Roll</th>
<th>Map time of day</th>
</tr>
</thead>
Expand All @@ -105,8 +102,8 @@
<td class="float">n/a</td>
<td class="float">n/a</td>
<td class="float">n/a</td>
<td>n/a</td>
<td>n/a</td>
<td class="float">n/a</td>
<td class="float">n/a</td>
</tr>
</tbody>
</table>
Expand Down
Loading

4 comments on commit 1e5e531

@nightlark
Copy link
Collaborator

@nightlark nightlark commented on 1e5e531 Nov 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Move the camera only when the game window is active.

I'll need to pull the new version to see how it works with all the other changes, but at least in the previous version I found moving the spectator mode camera around worked better when the machinima studio window was active instead of GW2, since the GW2 client also responded to key presses (most doing nothing since character movement is disabled). I bind Q, E, and R as hotkeys for attacking with a character, and some of the function keys map to abilities used by various classes, so occasionally while in spectator mode my character ends up using a skill when I press one of those keys.

Adding some error output for socket.io is good - there were a few instances where the electron app wouldn't connect to the server. On the bright side, more often than not it would connect regardless of the order the apps were launched (the first time notification is also useful, so that people know that both apps need to be running). The main problem I came across was launching GW2 after machinima-studio results in nothing happening - at minimum a similar notification about launch order would be useful.

Side note: I was initially surprised by the split into server and ui apps. It does have the benefit of allowing a separate computer (or tablet?) to be used as a controller, but I'm guessing the reason such an architecture was chosen is the difficulties of getting robot-js to work with electron?

@karliky
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nightlark first of all, your feedbaack is really appreciated, thank you so much!

This new version fixes a lot of bugs and also improves the interaction with the tool but most important is the support for all the easing functions and interpolation for the cinematic mode.

I'm curious about the situation you are describing because I've never seen the player casting spells or attacking when the spectate mode is active , would you mind to share a video with me? you can use http://recordit.co/ to record the video. Some time ago I found a way to disable the attacks so I might implement it if you need it. I'm also thinking about creating a new checkbox to customize all of these things sou you can move the camera and the player at the same time or even cast spells....

Yes, I think logs are good for the server (gw2/), if you want to debug the UI just press Ctrl+Shift+I and you'll be able to debug everything with the chrome dev tools. Definitely I'll take a look to the logs, thank you.

@nightlark
Copy link
Collaborator

@nightlark nightlark commented on 1e5e531 Nov 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@karliky Here's a recording (using the latest version) showing the casting of some spells while in spectate mode - http://recordit.co/xsFjotkm0V

If the method of disabling attacks involves another patch it might not be worth it since that is just one more thing that will need updating later on, and just having the machinima studio windows selected works well enough to avoid it. One way that I've stopped GW2 from getting button (and mouse, since GW2 still seems to be handling mouse movements when spectate mode is active, but the side effects are minimal) actions was using a WH_GETMESSAGE hook to intercept them, but with nodejs that might be tricky.

The new icon looks a lot better than the default electron icon.

@karliky
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nightlark Ok! that video looks interesting, I created this issue so from now we'll be talking there about this. #4

Please sign in to comment.