Skip to content

Commit

Permalink
Revert to manual rotation by mouse
Browse files Browse the repository at this point in the history
The simplified model rotation introduced with d1616a5 is not accurate
enough. The model will only be rotated if the mouse movement was larger
than a certain minimum threshold which makes aiming impossible. Although,
this was a nice commit in terms of performance and cutting down the code,
it is just not sufficient. All changes have been reverted.
  • Loading branch information
szapp committed Mar 5, 2017
1 parent d698424 commit c95dff3
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 35 deletions.
6 changes: 0 additions & 6 deletions _work/data/Scripts/Content/freeAim/_intern/collision.d
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,3 @@ func void freeAimTriggerCollisionCheck() {
&& (trigger.bitfield & zCTrigger_bitfield_reactToOnTouch) { return; }; // Object-reacting trigger
MEM_WriteInt(vobPtr, shooter); // The engine ignores the shooter
};

/* Disable damage animation. Taken from http://forum.worldofplayers.de/forum/threads/1474431?p=25057480#post25057480 */
func void freeAimDmgAnimation() {
var C_Npc victim; victim = _^(ECX);
if (Npc_IsPlayer(victim)) && (freeAimIsActive()) { EAX = 0; }; // Disable damage animation while aiming
};
5 changes: 3 additions & 2 deletions _work/data/Scripts/Content/freeAim/_intern/const.d
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const string FREEAIM_BREAK_FX = "freeAim_DESTROY"; // FX of project
const int FREEAIM_MAX_DIST = 5000; // 50m. Shooting/reticle adjustments. Do not change
const int FREEAIM_ACTIVE_PREVFRAME = 0; // Internal. Do not change
const int FREEAIM_G2CTRL_PREVFRAME = 0; // Internal. Do not change
const int FREEAIM_ROTATION_PREV = 0; // Internal. Do not change
const int FREEAIM_FOCUS_SPELL_FREE = 0; // Internal. Do not change
const int FREEAIM_FOCUS_COLLECTION = 1; // Internal. Do not change (change in ini-file)
const int FREEAIM_ARROWAI_REDIRECT = 0; // Used to redirect call-by-reference var. Do not change
Expand Down Expand Up @@ -79,11 +78,12 @@ const int zCLineCache__Line3D = 5289040; //0x50B450
const int zlineCache = 9257720; //0x8D42F8
const int oCGame__s_bUseOldControls = 9118144; //0x8B21C0
const int mouseEnabled = 9248108; //0x8D1D6C
const int mouseSensX = 9019720; //0x89A148
const int mouseDeltaX = 9246300; //0x8D165C
const int projectileDeflectOffNpcAddr = 6949734; //0x6A0B66
const int oCAIHuman__BowMode_695F2B = 6905643; //0x695F2B
const int oCAIHuman__BowMode_6962F2 = 6906610; //0x6962F2
const int oCAIHuman__PC_ActionMove_69A0BB = 6922427; //0x69A0BB
const int oCAIHuman__PC_Turnings_69AA11 = 6924817; //0x69AA11
const int zCWorld__AdvanceClock = 6447328; //0x6260E0 // Hook length 10
const int oCAIHuman__BowMode = 6905600; //0x695F00 // Hook length 6
const int oCAIHuman__BowMode_696296 = 6906518; //0x696296 // Hook length 5
Expand All @@ -102,3 +102,4 @@ const int oCNpcFocus__SetFocusMode = 7072800; //0x6BEC20 // Hook
const int oCAIHuman__MagicMode = 4665296; //0x472FD0 // Hook length 7
const int oCSpell__Setup_484BA9 = 4737961; //0x484BA9 // Hook length 6
const int spellAutoTurnAddr = 4665539; //0x4730C3 // Hook length 6
const int mouseUpdate = 5062907; //0x4D40FB // Hook length 5
44 changes: 44 additions & 0 deletions _work/data/Scripts/Content/freeAim/_intern/controls.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Input and controls manipulation
*
* G2 Free Aim v0.1.2 - Free aiming for the video game Gothic 2 by Piranha Bytes
* Copyright (C) 2016 mud-freak (@szapp)
*
* This file is part of G2 Free Aim.
* <http://github.com/szapp/g2freeAim>
*
* G2 Free Aim is free software: you can redistribute it and/or modify
* it under the terms of the MIT License.
* On redistribution this notice must remain intact and all copies must
* identify the original author.
*
* G2 Free Aim is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MIT License for more details.
*
* You should have received a copy of the MIT License
* along with G2 Free Aim. If not, see <http://opensource.org/licenses/MIT>.
*/

/* Mouse handling for manually turning the player model by mouse input */
func void freeAimManualRotation() {
if (!freeAimIsActive()) { return; };
var int deltaX; deltaX = mulf(mkf(MEM_ReadInt(mouseDeltaX)), MEM_ReadInt(mouseSensX)); // Get mouse change in x
if (deltaX == FLOATNULL) { return; }; // Only rotate if there was movement along x position
deltaX = mulf(deltaX, castToIntf(FREEAIM_ROTATION_SCALE)); // Turn rate
var int hAniCtrl; hAniCtrl = MEM_ReadInt(_@(hero)+2432); // oCNpc.anictrl
const int call = 0; var int null;
if (CALL_Begin(call)) {
CALL_IntParam(_@(null)); // 0 = disable turn animation (there is none while aiming anyways)
CALL_FloatParam(_@(deltaX));
CALL__thiscall(_@(hAniCtrl), oCAniCtrl_Human__Turn);
call = CALL_End();
};
};

/* Disable damage animation. Taken from http://forum.worldofplayers.de/forum/threads/1474431?p=25057480#post25057480 */
func void freeAimDmgAnimation() {
var C_Npc victim; victim = _^(ECX);
if (Npc_IsPlayer(victim)) && (freeAimIsActive()) { EAX = 0; }; // Disable damage animation while aiming
};
28 changes: 1 addition & 27 deletions _work/data/Scripts/Content/freeAim/_intern/init.d
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func void freeAim_Init() {
MEM_Info("");
// Controls
MEM_Info("Initializing controls.");
HookEngineF(mouseUpdate, 5, freeAimManualRotation); // Update the player model rotation by mouse input
HookEngineF(onDmgAnimationAddr , 9, freeAimDmgAnimation); // Disable damage animation while aiming
MemoryProtectionOverride(oCAIHuman__PC_Turnings_69AA11, 6); // Skip jump to allow rotation: jz to 0x69AC5C
// Ranged combat aiming and shooting
MEM_Info("Initializing ranged combat aiming and shooting.");
HookEngineF(oCAIHuman__BowMode_696296, 5, freeAimAnimation); // Update aiming animation
Expand Down Expand Up @@ -163,34 +163,8 @@ func void freeAimUpdateSettingsG2Ctrl(var int on) {
};
};

/* Enable/disable rotation while holding action key */
func void freeAimSetRotation(var int on) {
if (on) {
MEM_WriteByte(oCAIHuman__PC_Turnings_69AA11, ASMINT_OP_nop); // Skip jump to always have rotation control
MEM_WriteByte(oCAIHuman__PC_Turnings_69AA11+1, ASMINT_OP_nop);
MEM_WriteByte(oCAIHuman__PC_Turnings_69AA11+2, ASMINT_OP_nop);
MEM_WriteByte(oCAIHuman__PC_Turnings_69AA11+3, ASMINT_OP_nop);
MEM_WriteByte(oCAIHuman__PC_Turnings_69AA11+4, ASMINT_OP_nop);
MEM_WriteByte(oCAIHuman__PC_Turnings_69AA11+5, ASMINT_OP_nop);
FREEAIM_ROTATION_PREV = 1;
} else {
MEM_WriteByte(oCAIHuman__PC_Turnings_69AA11, /*0F*/ 15); //Revert to default: jz to 0x69AC5C
MEM_WriteByte(oCAIHuman__PC_Turnings_69AA11+1, /*84*/ 132);
MEM_WriteByte(oCAIHuman__PC_Turnings_69AA11+2, /*45*/ 69);
MEM_WriteByte(oCAIHuman__PC_Turnings_69AA11+3, /*02*/ 2);
MEM_WriteByte(oCAIHuman__PC_Turnings_69AA11+4, /*00*/ 0);
MEM_WriteByte(oCAIHuman__PC_Turnings_69AA11+5, /*00*/ 0);
FREEAIM_ROTATION_PREV = -1;
};
};

/* Check whether free aiming should be activated */
func int freeAimIsActive() {
if (final()) {
var int ret; ret = MEMINT_PopInt();
if (FREEAIM_ROTATION_PREV != ret*2-1) { freeAimSetRotation(ret); }; // Enable/Disable rotation
ret;
};
if (!STR_ToInt(MEM_GetGothOpt("FREEAIM", "enabled"))) // Free aiming is disabled in the menu
|| (!MEM_ReadInt(mouseEnabled)) { // Mouse controls are disabled
if (FREEAIM_ACTIVE_PREVFRAME != -1) { freeAimUpdateSettings(0); }; // Update internal settings (turn off)
Expand Down
1 change: 1 addition & 0 deletions _work/data/Scripts/Content/freeAim/freeAim.src
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ config\settings.d

_intern\activeSpell.d
_intern\init.d
_intern\controls.d
_intern\ccommands.d
_intern\debug.d
_intern\aimVob.d
Expand Down

0 comments on commit c95dff3

Please sign in to comment.