Skip to content

Commit

Permalink
Избавляемся от использования IsGLEnabled, реализуем функцию изменения…
Browse files Browse the repository at this point in the history
… подсказки при подборе предмета, добавляем комменты с пояснениями патчей
  • Loading branch information
FreeZoneMods committed Sep 29, 2024
1 parent 67edd07 commit 836cff5
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 126 deletions.
42 changes: 38 additions & 4 deletions ActorUtils.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2770,7 +2770,7 @@ procedure UpdateFOV(act:pointer);
end;
end;

if ((GetGLStatus(wpn)=1) or ((GetGLStatus(wpn)=2) and IsGLAttached(wpn))) and IsGLEnabled(wpn) then begin
if IsGrenadeMode(wpn) then begin
zoom_fov:=GetCachedCfgParamFloatDef(cached_hud_fov_gl_zoom_factor, GetHUDSection(wpn), 'hud_fov_gl_zoom_factor', hud_fov);
zoom_fov_section:=nil;
end else if (GetScopeStatus(wpn)=2) and IsScopeAttached(wpn) then begin
Expand Down Expand Up @@ -3539,7 +3539,7 @@ procedure SetDisableInputStatus(status:boolean); stdcall;

movzx eax, status
mov ebx, xrgame_addr
mov byte ptr [ebx+$64db8a], al
mov byte ptr [ebx+$64db8a], al // g_bDisableAllInput

pop ebx
pop eax
Expand Down Expand Up @@ -4032,6 +4032,35 @@ procedure CInventory__CanTakeItem_Conditions(); stdcall;
jmp edx
end;

procedure SetTakeItemHint(hint:pshared_str; inventory_item:pointer); stdcall;
var
sect:PAnsiChar;
fun:PAnsiChar;
hint_text:PAnsiChar;
begin
sect:=GetSection(inventory_item);

if (sect<>nil) and game_ini_line_exist(sect, 'take_hint_function') then begin
fun:=game_ini_read_string(sect, 'take_hint_function');
hint_text:=script_pchar_call(fun, '', GetID(inventory_item), false, '');
assign_string(hint, hint_text)
end;
end;

procedure CActor__shedule_Update_changetakeitemmessage_Patch(); stdcall;
asm
pushad
mov ecx,[esi+$510]
mov edx,[ecx]
mov eax,[edx+$8C]
call eax // m_pObjectWeLookingAt->cast_inventory_item()
push eax
lea ecx,[esi+$518] //m_sDefaultObjAction
push ecx
call SetTakeItemHint
popad
end;

function GetActorTorchDist():single; stdcall;
//Âîçâðàòèòü äèñòàíöèþ çàñâåòà èëè -1, åñëè ñâåòà íåò
var
Expand Down Expand Up @@ -4736,7 +4765,7 @@ function Init():boolean; stdcall;
jmp_addr:= xrgame_addr+$2F8102;
if not WriteJump(jmp_addr, cardinal(@OnOutfitOrHelmInRuck_Patch), 5, true) then exit;


// â CActor__g_cl_CheckControls êîððåêòèðóåì ñêîðîñòü äâèæåíèÿ àêòîðà (ïîñëå scale = m_fWalkAccel/scale äîìíîæàåì íà äîïîëíèòåëüíûé êîýôôèöèåíò)
jmp_addr:= xrgame_addr+$269ab0;
if not WriteJump(jmp_addr, cardinal(@CorrectActorSpeed), 6, true) then exit;

Expand All @@ -4754,6 +4783,7 @@ function Init():boolean; stdcall;
jmp_addr:= xrgame_addr+$45CA70;
if not WriteJump(jmp_addr, cardinal(@CUIMotionIcon__Update_Patch), 8, true) then exit;

// Êîððåêöèÿ äâèæåíèé ìûøè â CActor::IR_OnMouseMove ïîñëå âû÷èñëåíèÿ scale
jmp_addr:= xrgame_addr+$277CC3;
if not WriteJump(jmp_addr, cardinal(@CActor__IR_OnMouseMove_CorrectMouseSense_Patch), 16, true) then exit;

Expand Down Expand Up @@ -4790,7 +4820,11 @@ function Init():boolean; stdcall;
jmp_addr:=xrGame_addr+$2a9ce3;
if not WriteJump(jmp_addr, cardinal(@CInventory__CanTakeItem_Conditions), 5, true) then exit;

// Óäëèíåííèå ðóê àêòîðà - ÷òîáû ìîã âçÿòü õàáàð èç íû÷åê â êàáèíàõ è ò.ï
//Â CActor::shedule_Update êàñòîìèçèðóåì âûáîð ñîîáùåíèÿ äëÿ m_sInventoryItemUseAction
jmp_addr:=xrGame_addr+$262c02;
if not WriteJump(jmp_addr, cardinal(@CActor__shedule_Update_changetakeitemmessage_Patch), 20, true) then exit;

// Óäëèíåííèå ðóê àêòîðà - ÷òîáû ìîã âçÿòü õàáàð èç íû÷åê â êàáèíàõ è ò.ï (ïàò÷ â CActor::shedule_Update âûðàæåíèÿ RQ.range<2.0f)
jmp_addr:=cardinal(@g_pickup_distance);
if not WriteBufAtAdr(xrGame_addr+$2629a3, @jmp_addr, sizeof(jmp_addr)) then exit;

Expand Down
68 changes: 23 additions & 45 deletions HudItemUtils.pas
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ procedure set_addons_state(wpn:pointer; state:cardinal); stdcall;
function IsScopeAttached(wpn:pointer):boolean; stdcall;
function IsSilencerAttached(wpn:pointer):boolean; stdcall;
function IsGLAttached(wpn:pointer):boolean; stdcall;
function IsGLEnabled(wpn:pointer):boolean; stdcall; //ïåðåä âûçîâîì - îáÿçàòåëüíî óáåäèòüñÿ, ÷òî ãðàíàòîìåò íà îðóæèè âîîáùå ÅÑÒÜ! Íåêîòîðûå êëàññû îðóæèÿ íå ïîääåðæèâàþò ãðàíàòîìåò, è òîãäà ôóíêöèÿ ìîæåò âîçâðàòèòü ìóñîð èëè äàæå ñãåíåðèðîâàòü âûëåò!
function IsGLEnabled(wpn:pointer):boolean; stdcall; //UNSAFE! Ëó÷øå èñïîëüçîâàòü IsGrenadeMode! Åñëè íå âûõîäèò, òî ïåðåä âûçîâîì îáÿçàòåëüíî óáåäèòüñÿ, ÷òî ãðàíàòîìåò íà îðóæèè âîîáùå ÅÑÒÜ! Íåêîòîðûå êëàññû îðóæèÿ íå ïîääåðæèâàþò ãðàíàòîìåò, è òîãäà ôóíêöèÿ ìîæåò âîçâðàòèòü ìóñîð èëè äàæå ñãåíåðèðîâàòü âûëåò!
procedure SetGLEnabled(wpn:pointer; state:boolean); stdcall;
function IsWeaponJammed(wpn:pointer):boolean; stdcall;
function CurrentQueueSize(wpn:pointer):integer; stdcall;
Expand Down Expand Up @@ -243,7 +243,7 @@ function CWeapon__CheckForMisfire(wpn:pointer):boolean; stdcall;


implementation
uses BaseGameData, gunsl_config, sysutils, ActorUtils, Misc, xr_BoneUtils, windows, dynamic_caster, xr_Cartridge, xr_strings;
uses BaseGameData, gunsl_config, sysutils, ActorUtils, Misc, xr_BoneUtils, windows, dynamic_caster, xr_Cartridge, xr_strings, Vector;
var
PlayHudAnim_Func:cardinal;
_pps_HudFlags:pcardinal;
Expand Down Expand Up @@ -424,64 +424,44 @@ function ModifyFloatUpgradedValue(wpn:pointer; key:PChar; def:single):single; st
end;

function GetAmmoInMagCount(wpn:pointer):cardinal; stdcall;
asm
pushad
pushfd
mov ebx, wpn

pushad
push ebx
call GetGLStatus
cmp eax, 0
popad
je @use_main

push ebx
call IsGLEnabled
cmp al, 0
jne @use_alter

@use_main:
mov edx, [ebx+$6CC]
sub edx, [ebx+$6C8]
jmp @divide

@use_alter:
mov edx, [ebx+$7F0]
sub edx, [ebx+$7EC]
jmp @divide
var
pstart, pend:cardinal;
ptr:pxr_vector;
begin
result:=0;
if wpn = nil then exit;

@divide:
movzx eax, dx
shr edx, 16
mov ebx, $3c;
div bx
if not IsGrenadeMode(wpn) then
ptr:= pxr_vector(PChar(wpn)+$6C8)
else
ptr:= pxr_vector(PChar(wpn)+$7EC);

mov @result, eax
pstart:=cardinal(ptr.start);
pend:=cardinal(ptr.last);

popfd
popad
result:=(pend-pstart) div sizeof(CCartridge);
end;


function GetAmmoInGLCount(wpn:pointer):cardinal; stdcall;
var
pstart, pend, gl_status:cardinal;
ptr:pointer;
ptr:pxr_vector;
begin
result:=0;

if wpn = nil then exit;

gl_status:=GetGLStatus(wpn);
if (gl_status=0) or ((gl_status=2) and not IsGLAttached(wpn)) then exit;

if IsGrenadeMode(wpn) then
ptr:= PChar(wpn)+$6C8
ptr:= pxr_vector(PChar(wpn)+$6C8)
else
ptr:= PChar(wpn)+$7EC;
ptr:= pxr_vector(PChar(wpn)+$7EC);

pstart:=(pcardinal(ptr))^;
pend:=(pcardinal(PChar(ptr)+4))^;
pstart:=cardinal(ptr.start);
pend:=cardinal(ptr.last);

result:=(pend-pstart) div sizeof(CCartridge);
end;
Expand Down Expand Up @@ -837,6 +817,7 @@ function IsGLAttached(wpn:pointer):boolean; stdcall;
@finish:
end;

// UNSAFE! Try to use IsGrenadeMode instead
function IsGLEnabled(wpn:pointer):boolean; stdcall;
asm
mov @result, 0
Expand Down Expand Up @@ -1431,14 +1412,11 @@ function GetMagCapacity(wpn:pointer):cardinal; stdcall;
ammotype:integer;
param:string;
sect:PChar;
gl_status:cardinal;
begin
result:=0;
if wpn = nil then exit;

gl_status:=GetGLStatus(wpn);

if ((gl_status=1) or ((gl_status=2) and (IsGLAttached(wpn)))) and IsGLEnabled(wpn) then begin
if IsGrenadeMode(wpn) then begin
ptr:= PChar(wpn)+$7E8;
ammotype:=-1;
end else begin
Expand Down
2 changes: 1 addition & 1 deletion LensDoubleRender.pas
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ procedure CCameraManager__Update_Lens_FOV_manipulation(value:pSingle); stdcall;
// Ëèíçà îòêëþ÷åíà â íàñòðîéêàõ. Åñëè ìû â ðåæèìå ïðèöåëèâàíèÿ - âñå êàäðû ðåíäåðèì ñ óêàçàííûì ôîâ
wpn:=GetActorActiveItem();
wpn:=dynamic_cast(wpn, 0, RTTI_CHudItemObject, RTTI_CWeapon, false);
if (wpn<>nil) and (GetAimFactor(wpn) > 0.999) and not (((GetGLStatus(wpn)=1) or IsGLAttached(wpn)) and IsGLEnabled(wpn)) and IsLensedScopeInstalled(wpn) then begin
if (wpn<>nil) and (GetAimFactor(wpn) > 0.999) and (not IsGrenadeMode(wpn)) and IsLensedScopeInstalled(wpn) then begin
buf:=GetBuffer(wpn);
if (buf=nil) or not buf.IsAlterZoomMode() then begin
value^:=GetLensFOV(value^);
Expand Down
2 changes: 1 addition & 1 deletion Throwable.pas
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ procedure SetImmediateThrowStatus(CMissile:pointer; status:boolean); stdcall;
pushad
mov ecx, CMissile
movzx eax, [status]
mov [ecx+$33c], eax
mov [ecx+$33c], eax // m_throw
popad
end;

Expand Down
3 changes: 3 additions & 0 deletions UIUtils.pas
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ function GetPDA():pCUIPDAWnd; stdcall;
end;

function IsInventoryShown():boolean; stdcall;
// CurrentGameUI()->ActorMenu().IsShown()
begin
asm
mov @result, 0
Expand Down Expand Up @@ -2821,6 +2822,8 @@ function Init():boolean;stdcall;
//CUIActorMenu::InitInventoryMode - xrgame.dll+46e530
//CUIActorMenu::InitInventoryContents - xrgame.dll+46e310

//CUICustomMap::Initialize - xrgame.dll+447210


result:=true;
end;
Expand Down
4 changes: 1 addition & 3 deletions WeaponAdditionalBuffer.pas
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,6 @@ function CanAimNow(wpn:pointer):boolean;stdcall;
var
tmp:pointer;
sect:PAnsiChar;
gl_status:integer;
begin
result:=true;
if IsActorSuicideNow() or IsActorPlanningSuicide() or IsControllerPreparing() then begin
Expand All @@ -911,8 +910,7 @@ function CanAimNow(wpn:pointer):boolean;stdcall;
end;

if result then begin
gl_status:=GetGLStatus(wpn);
if ((gl_status=1) or ((gl_status=2) and (IsGLAttached(wpn)))) and IsGLEnabled(wpn) then begin
if IsGrenadeMode(wpn) then begin
if IsScopeAttached(wpn) then begin
sect:=GetCurrentScopeSection(wpn);
end else begin
Expand Down
16 changes: 6 additions & 10 deletions WeaponAmmoCounter.pas
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ procedure SwapFirstLastAmmo(wpn:pointer);stdcall;
var
cs, ce:pCCartridge;
tmp:CCartridge;
cnt, gl_status:cardinal;
cnt:cardinal;
begin
gl_status:=GetGLStatus(wpn);
if ((gl_status=1) or ((gl_status=2) and IsGLAttached(wpn))) and IsGLEnabled(wpn) then exit;
if IsGrenadeMode(wpn) then exit;
cnt:=GetAmmoInMagCount(wpn);
if cnt>1 then begin
cnt:=cnt-1;
Expand All @@ -36,10 +35,9 @@ procedure SwapLastPrevAmmo(wpn:pointer);stdcall;
var
cs, ce:pCCartridge;
tmp:CCartridge;
cnt, gl_status:cardinal;
cnt:cardinal;
begin
gl_status:=GetGLStatus(wpn);
if ((gl_status=1) or ((gl_status=2) and IsGLAttached(wpn))) and IsGLEnabled(wpn) then exit;
if IsGrenadeMode(wpn) then exit;
cnt:=GetAmmoInMagCount(wpn);
if cnt>1 then begin
cnt:=cnt-1;
Expand All @@ -57,15 +55,13 @@ procedure CWeaponMagazined__OnAnimationEnd_DoReload(wpn:pointer); stdcall;
var
buf: WpnBuf;
def_magsize, mod_magsize, curammocnt:integer;
gl_status:cardinal;
begin
buf:=GetBuffer(wpn);
//åñëè áóôåðà íåò èëè ìû óæå ïåðåçàðÿäèëècü èëè ó íàñ ðåæèì ïîäñòâîëà - íè÷åãî îñîáåííîãî íå äåëàåì
if (buf=nil) then begin virtual_CWeaponMagazined__ReloadMagazine(wpn); exit; end;

if buf.IsReloaded() then begin buf.SetReloaded(false); exit; end;
gl_status:=GetGLStatus(wpn);
if (((gl_status=1) or ((gl_status=2) and IsGLAttached(wpn))) and IsGLEnabled(wpn)) then begin virtual_CWeaponMagazined__ReloadMagazine(wpn); exit; end;
if IsGrenadeMode(wpn) then begin virtual_CWeaponMagazined__ReloadMagazine(wpn); exit; end;

//ïîñìîòðèì, êàêîâ ðàçìåð ìàãàçèíà ó îðóæèÿ è ñêîëüêî ïàòðîíîâ â íåì ñåé÷àñ
def_magsize:=GetMagCapacity(wpn);
Expand Down Expand Up @@ -514,7 +510,7 @@ function GetTotalGrenadesCountInInventory(wpn:pointer):cardinal;stdcall;
exit;
end;

g_m:=IsGLEnabled(wpn);
g_m:=IsGrenadeMode(wpn);
cnt:=GetGLAmmoTypesCount(wpn);
result:=0;

Expand Down
6 changes: 2 additions & 4 deletions WeaponEvents.pas
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,6 @@ procedure OnCWeaponNetSpawn_end(wpn:pointer);stdcall;
if WpnCanShoot(wpn) then begin
buf:=GetBuffer(wpn);
if (buf<>nil) then begin
// if (IsGLAttached(wpn)) then log(booltostr(ISGLEnabled(wpn), true));

if (length(buf.ammos)>0) and (length(buf.ammos)=integer(GetAmmoInMagCount(wpn))) then begin
for i:=0 to length(buf.ammos)-1 do begin
sect:=GetMainCartridgeSectionByType(wpn, buf.ammos[i]);
Expand Down Expand Up @@ -946,7 +944,7 @@ procedure OnEmptyClick(wpn:pointer);stdcall;
anm_started:=false;

//Ïðè ïàò÷èíãå ìû âûðåçàëè âîñïðîèçâåäåíèå çâóêà. Èñïðàâèì ýòî íåäîðàçóìåíèå îäíîâðåìåííî ñ ïðîèãðûâàíèåì àíèìû.
if not (((GetGLStatus(wpn)=1) or IsGLAttached(wpn)) and IsGLEnabled(wpn)) and IsWeaponJammed(wpn) then begin
if not IsGrenadeMode(wpn) and IsWeaponJammed(wpn) then begin
txt := 'gunsl_msg_weapon_jammed';
if IsAimNow(wpn) or IsHolderInAimState(wpn) then begin
anm_started:=WeaponAdditionalBuffer.PlayCustomAnimStatic(wpn, 'anm_fakeshoot_aim', 'sndJammedClick', nil, 0, false, true)
Expand Down Expand Up @@ -1908,7 +1906,7 @@ procedure CWeapon__OnZoomIn(wpn:pointer); stdcall;
buf:WpnBuf;
scope_sect:PChar;
begin
if IsGLAttached(wpn) and IsGLEnabled(wpn) then begin
if IsGrenadeMode(wpn) then begin
scope_sect:=GetSection(wpn);
if game_ini_line_exist(scope_sect, 'gl_zoom_factor') then begin
SetZoomFactor(wpn, game_ini_r_single(scope_sect, 'gl_zoom_factor'));
Expand Down
13 changes: 5 additions & 8 deletions burer.pas
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ function IsActorLookTurnedAway(burer:pointer):boolean; stdcall;

function IsWeaponDangerous(itm:pointer; burer:pointer):boolean; stdcall;
var
gl_status:cardinal;
in_gl:boolean;
curanm:PAnsiChar;
begin
result:=false;
Expand All @@ -115,9 +113,7 @@ function IsWeaponDangerous(itm:pointer; burer:pointer):boolean; stdcall;
end else if IsThrowable(itm) then begin
result:=false;
end else if WpnCanShoot(itm) and (GetCurrentAmmoCount(itm) > 0) then begin
gl_status:=GetGLStatus(itm);
in_gl:= ((gl_status=1) or ((gl_status=2) and IsGLAttached(itm))) and IsGLEnabled(itm);
if in_gl then begin
if IsGrenadeMode(itm) then begin
result:=true;
end else if IsWeaponJammed(itm) or (GetCurrentState(itm) = EWeaponStates__eReload) then begin
result:=false;
Expand All @@ -129,7 +125,6 @@ function IsWeaponDangerous(itm:pointer; burer:pointer):boolean; stdcall;

function IsWeaponReadyForBigBoom(itm:pointer; was_shot:pboolean):boolean; stdcall;
var
gl_status:cardinal;
buf:WpnBuf;
const
SHOT_SAFETY_TIME_DELTA:cardinal=2000;
Expand All @@ -142,8 +137,7 @@ function IsWeaponReadyForBigBoom(itm:pointer; was_shot:pboolean):boolean; stdcal
if itm<>nil then begin
result:=(dynamic_cast(itm, 0, RTTI_CHudItemObject, RTTI_CWeaponRG6, false)<>nil) or (dynamic_cast(itm, 0, RTTI_CHudItemObject, RTTI_CWeaponRPG7, false)<>nil);
if not result and WpnCanShoot(itm) then begin
gl_status:=GetGLStatus(itm);
if ((gl_status=1) or ((gl_status=2) and IsGLAttached(itm))) and IsGLEnabled(itm) then begin
if IsGrenadeMode(itm) then begin
result:=true;
end;
end;
Expand Down Expand Up @@ -774,6 +768,7 @@ function CStateBurerShield__check_completion_MayIgnoreShieldTime(burer:pointer;

if not result and IsKnife(itm) and IsBurerKnifeSelfKick() then begin
AssignSelfKick();
virtual_CHudItem_SwitchState(itm, EWeaponStates__eFire);
end;

if not result then begin
Expand Down Expand Up @@ -2276,6 +2271,8 @@ function Init():boolean; stdcall;
if not WriteJump(jmp_addr, cardinal(@CStateBurerAttack__check_control_start_conditions_reimpl_Patch), 5, false) then exit;
g_antiaim_allowed:=0;

// [todo] Â anti_aim_ability::check_update_condition ìîæíî äîáàâèòü çàâåðøåíèå, åñëè àêòîð ñêðûëñÿ èç ïîëÿ çðåíèÿ

//CPHCollisionDamageReceiver::CollisionHit - xrgame+28f970
//xrgame+$101c60 - CBurer::DeactivateShield

Expand Down
Loading

0 comments on commit 836cff5

Please sign in to comment.