Skip to content

Commit

Permalink
first implementation for time of day
Browse files Browse the repository at this point in the history
  • Loading branch information
karliky committed Apr 22, 2020
1 parent 01c6a55 commit ca5021b
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/core/domain/environment/getEnvPtr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function GetEnvPtr(Game, memory, Module, offsets) {
return () => {
const timeOfDay = Module + offsets[Game.client].environment.version[Game.build].timeOfDay;

return {
timeOfDay,
};
};
}

module.exports = GetEnvPtr;
11 changes: 11 additions & 0 deletions src/core/domain/environment/setTimeOfday.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

function SetTimeOfday(Game, Memory, Offsets, Module) {
const timeOfDayBuffer = new Buffer(0x4);
return (environmentStruct, { hour, minutes }) => {
const timeNormalized = ((3600 * hour) + (60 * minutes)) / 86400;
timeOfDayBuffer.writeFloatLE(timeNormalized);
Memory.writeData(environmentStruct.timeOfDay, timeOfDayBuffer, timeOfDayBuffer.byteLength);
};
}

module.exports = SetTimeOfday;
9 changes: 8 additions & 1 deletion src/core/logic/patterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,14 @@ export const alpha = {
fix: new Buffer([0xE8, 0x94, 0x80, 0xFA, 0xFF, 0xB9, 0x09, 0x00, 0x00, 0x00, 0x8D, 0xB5, 0x70, 0xFF, 0xFF, 0xFF, 0x90, 0x90])
}
}
}
},
environment: {
version: {
['0.5.3']: {
timeOfDay: 0xCB23B4
}
}
},
};

export const tbc = {
Expand Down
9 changes: 9 additions & 0 deletions src/core/manager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable consistent-return, no-restricted-syntax,padded-blocks */
const createCamera = require('./logic/camera.js');
const createGetCametaPtr = require('./domain/getCameraPtr');
const createGetEnvPtr = require('./domain/environment/getEnvPtr');
const createEnableSpectate = require('./domain/enableSpectate');
const createDisableSpectate = require('./domain/disableSpectate');
const createEnableViewMatrixUpdate = require('./domain/enableViewMatrixUpdate');
Expand All @@ -10,6 +11,7 @@ const createEnableKeyboardControls = require('./domain/enableKeyboardControls');
const createSetPosition = require('./domain/setPosition');
const createSetCameraView = require('./domain/setCameraView');
const createSetCollision = require('./domain/setCollision');
const createSetTimeOfday = require('./domain/environment/setTimeOfday');
const createSetSpeed = require('./domain/setSpeed');

module.exports = (process, Module, Memory, window, Offsets) => {
Expand Down Expand Up @@ -50,7 +52,14 @@ module.exports = (process, Module, Memory, window, Offsets) => {
SetCameraView,
SetCollision,
)();

const setTimeOfday = createSetTimeOfday(Game, Memory, Offsets, Module);
const environmentStruct = createGetEnvPtr(Game, Memory, Module, Offsets)();
const environment = {
setTimeOfday: (timeOfDay) => setTimeOfday(environmentStruct, timeOfDay),
};
return {
camera,
environment,
};
};
11 changes: 10 additions & 1 deletion src/renderer/components/sections/general.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div class="field">
<label class="label is-normal">Time of day</label>
<p class="control">
<input class="input range ltpurple" type="text" placeholder="00:00">
<input class="input range ltpurple" type="time" v-on:change="setTimeOfDay" v-on:input="setTimeOfDay" value="12:30">
</p>
</div>
</div>
Expand Down Expand Up @@ -75,6 +75,15 @@
<script>
export default {
name: 'general',
methods: {
setTimeOfDay (element) {
const time = element.target.value;
if (!time) return;
const hour = time.split(":")[0];
const minutes = time.split(":")[1];
this.$store.commit('setTimeOfDay', { hour, minutes });
}
},
data() {
return {};
},
Expand Down
16 changes: 16 additions & 0 deletions src/renderer/store/modules/environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

export default {
state: {
timeOfDay: { hour: 0, minutes: 0 },
},
getters: {
timeOfDay: state => state.timeOfDay,
},
mutations: {
setTimeOfDay(state, TimeOfDay) {
const core = this.getters.core.environment;
state.timeOfDay = TimeOfDay;
core.setTimeOfday({ ...TimeOfDay });
},
},
};

0 comments on commit ca5021b

Please sign in to comment.