local ev = require 'lib.samp.events'
local memory = require 'memory'
local cef = require('CEF Events')
local inicfg = require 'inicfg'
local directIni = 'setspawn.ini'
local ini = inicfg.load(inicfg.load({
main = {
hpt = true,
hphud = true,
},
}, directIni))
inicfg.save(ini, directIni)
local alpha = 0xFFffffff
local alphabg = 0xFF000000
local alphabar = 1
local visible = true
function ev.onSendClickTextDraw(id)
if invopened and id == 65535 then
invopened = false
end
end
function onReceiveRpc(id, bs, priority, reliability)
if id == 83 then
--print(raknetBitStreamReadBool(bs))
invopened = raknetBitStreamReadBool(bs)
end
end
function darkenColor(color, factor)
local r = math.floor((bit.rshift(bit.band(color, 0xFF0000), 16) * factor))
local g = math.floor((bit.rshift(bit.band(color, 0x00FF00), 8) * factor))
local b = math.floor((bit.band(color, 0x0000FF) * factor))
return (bit.bor(bit.band(color, 0xFF000000), bit.lshift(r, 16), bit.lshift(g, 8), b))
end
local imgui = require("mimgui")
local ffi = require("ffi")
imgui.OnFrame(
function() return isSampAvailable() end,
function(self)
self.HideCursor = true
if not isPauseMenuActive() and sampIsLocalPlayerSpawned() and isPlayerPlaying(playerHandle) and not sampIsScoreboardOpen() and not invopened and visible then
imgui.PushStyleColor(imgui.Col.WindowBg, imgui.ImVec4(0,0,0,0))
imgui.PushStyleVarVec2(imgui.StyleVar.WindowTitleAlign, imgui.ImVec2(0.0, 0.0))
HP = getCharHealth(playerPed)
barWidthHP = math.min(181 * HP / 100 - 2 * 3, 181 - 2 * 3)
local sizeHP = imgui.ImVec2(barWidthHP, 21 - 2 * 3 - 4)
AP = getCharArmour(playerPed)
barWidthAP = math.min(181 * AP / 100 - 2 * 3, 181 - 2 * 3)
local sizeAP = imgui.ImVec2(barWidthAP, 21 - 2 * 3 - 4)
imgui.SetNextWindowPos(imgui.ImVec2(1636, 104), imgui.Cond.Always, imgui.ImVec2(0.0, 0.0))
imgui.PushStyleColor(imgui.Col.Border, imgui.ImVec4(0,0,0,0))
imgui.End()
end
end)
ffi.cdef [[
typedef struct stRECT
{
int left, top, right, bottom;
} RECT;
typedef struct stID3DXFont
{
struct ID3DXFont_vtbl* vtbl;
} ID3DXFont;
struct ID3DXFont_vtbl
{
void* QueryInterface; // STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
void* AddRef; // STDMETHOD_(ULONG, AddRef)(THIS) PURE;
uint32_t (__stdcall * Release)(ID3DXFont* font); // STDMETHOD_(ULONG, Release)(THIS) PURE;
// ID3DXFont
void* GetDevice; // STDMETHOD(GetDevice)(THIS_ LPDIRECT3DDEVICE9 *ppDevice) PURE;
void* GetDescA; // STDMETHOD(GetDescA)(THIS_ D3DXFONT_DESCA *pDesc) PURE;
void* GetDescW; // STDMETHOD(GetDescW)(THIS_ D3DXFONT_DESCW *pDesc) PURE;
void* GetTextMetricsA; // STDMETHOD_(BOOL, GetTextMetricsA)(THIS_ TEXTMETRICA *pTextMetrics) PURE;
void* GetTextMetricsW; // STDMETHOD_(BOOL, GetTextMetricsW)(THIS_ TEXTMETRICW *pTextMetrics) PURE;
void* GetDC; // STDMETHOD_(HDC, GetDC)(THIS) PURE;
void* GetGlyphData; // STDMETHOD(GetGlyphData)(THIS_ UINT Glyph, LPDIRECT3DTEXTURE9 *ppTexture, RECT *pBlackBox, POINT *pCellInc) PURE;
void* PreloadCharacters; // STDMETHOD(PreloadCharacters)(THIS_ UINT First, UINT Last) PURE;
void* PreloadGlyphs; // STDMETHOD(PreloadGlyphs)(THIS_ UINT First, UINT Last) PURE;
void* PreloadTextA; // STDMETHOD(PreloadTextA)(THIS_ LPCSTR pString, INT Count) PURE;
void* PreloadTextW; // STDMETHOD(PreloadTextW)(THIS_ LPCWSTR pString, INT Count) PURE;
int (__stdcall * DrawTextA)(ID3DXFont* font, void* pSprite, const char* pString, int Count, RECT* pRect, uint32_t Format, uint32_t Color); // STDMETHOD_(INT, DrawTextA)(THIS_ LPD3DXSPRITE pSprite, LPCSTR pString, INT Count, LPRECT pRect, DWORD Format, D3DCOLOR Color) PURE;
void* DrawTextW; // STDMETHOD_(INT, DrawTextW)(THIS_ LPD3DXSPRITE pSprite, LPCWSTR pString, INT Count, LPRECT pRect, DWORD Format, D3DCOLOR Color) PURE;
void (__stdcall * OnLostDevice)(ID3DXFont* font); // STDMETHOD(OnLostDevice)(THIS) PURE;
void (__stdcall * OnResetDevice)(ID3DXFont* font); // STDMETHOD(OnResetDevice)(THIS) PURE;
};
uint32_t D3DXCreateFontA(void* pDevice, int Height, uint32_t Width, uint32_t Weight, uint32_t MipLevels, bool Italic, uint32_t CharSet, uint32_t OutputPrecision, uint32_t Quality, uint32_t PitchAndFamily, const char* pFaceName, ID3DXFont** ppFont);
]]
local d3dx9_43 = ffi.load('d3dx9_43.dll')
function d3dxfont_create(name, height, charset)
charset = charset or 1
local d3ddev = ffi.cast('void*', getD3DDevicePtr())
local pfont = ffi.new('ID3DXFont*[1]', {nil})
if tonumber(d3dx9_43.D3DXCreateFontA(d3ddev, height, 0, 600, 1, false, charset, 0, 4, 0, name, pfont)) < 0 then
return nil
end
return pfont[0]
end
function d3dxfont_draw(font, text, rect, color, format)
local prect = ffi.new('RECT[1]', {{rect[1], rect[2], rect[3], rect[4]}})
return font.vtbl.DrawTextA(font, nil, text, -1, prect, format, color)
end
function onD3DDeviceLost()
if fonts_loaded then
font_arial.vtbl.OnLostDevice(font_arial)
end
end
function onD3DDeviceReset()
if fonts_loaded then
font_arial.vtbl.OnResetDevice(font_arial)
end
end
local font = renderCreateFont('Tahoma', 12, 0)
function onD3DPresent() -- в этом событии и осуществляются все операции рисования с помощью DirectX
if fonts_loaded and ini.main.hphud and not isPauseMenuActive() and isPlayerPlaying(playerHandle) and not sampIsScoreboardOpen() and not invopened and visible then
local HP = getCharHealth(playerPed)
local AP = getCharArmour(playerPed)
local length = renderGetFontDrawTextLength(font, tostring(HP))
local sw, sh = getScreenResolution()
local nx, ny = convertGameScreenCoordsToWindowScreenCoords(573.1, 66)
local text = ini.main.hpt and 'HP' or ''
local offset = ini.main.hpt and 0 or 11
d3dxfont_draw(font_arial, HP..''..text, {nx- length/2+offset, ny+2, sw, sh}, alphabg, 0x10)
d3dxfont_draw(font_arial, HP..''..text, {nx- length/2+offset, ny-2, sw, sh}, alphabg, 0x10)
d3dxfont_draw(font_arial, HP..''..text, {nx+2- length/2+offset, ny, sw, sh}, alphabg, 0x10)
d3dxfont_draw(font_arial, HP..''..text, {nx-2- length/2+offset, ny, sw, sh}, alphabg, 0x10)
d3dxfont_draw(font_arial, HP..''..text, {nx- length/2+offset, ny, sw, sh}, alpha, 0x10) -- выводим все символы шрифта Wingdings
if AP > 0 then
local nx, ny = convertGameScreenCoordsToWindowScreenCoords(573.1, 44)
local length = renderGetFontDrawTextLength(font, tostring(AP))
local text = ini.main.hpt and 'AP' or ''
d3dxfont_draw(font_arial, AP..''..text, {nx- length/2+offset, ny+2, sw, sh}, alphabg, 0x10)
d3dxfont_draw(font_arial, AP..''..text, {nx- length/2+offset, ny-2, sw, sh}, alphabg, 0x10)
d3dxfont_draw(font_arial, AP..''..text, {nx+2- length/2+offset, ny, sw, sh}, alphabg, 0x10)
d3dxfont_draw(font_arial, AP..''..text, {nx-2- length/2+offset, ny, sw, sh}, alphabg, 0x10)
d3dxfont_draw(font_arial, AP..''..text, {nx- length/2+offset, ny, sw, sh}, alpha, 0x10) -- выводим все символы шрифта Wingdings
end
end
end
function onExitScript()
if fonts_loaded then
font_arial.vtbl.Release(font_arial)
end
end
function main()
memory.setfloat(0xCF1055, 0, true) -- длинна полоски хп 109.0
memory.write(0x5892D8, 0xCF1055, 4, true)
memory.setfloat(0xCF1060, 0, true) -- высота полоски хп 9.0
memory.write(0x589358, 0xCF1060, 4, true)
memory.setfloat(0xCF1155, 0, true) -- размер брони X 62.0
memory.write(0x58915B+2, 0xCF1155, 4, true)
memory.setfloat(0xCF1160, 0, true) -- размер брони Y 9.0
memory.write(0x589144+2, 0xCF1160, 4, true)
draw = true
font_arial = d3dxfont_create('Tahoma', 23)
fonts_loaded = true
sampRegisterChatCommand('hpt', function()
ini.main.hpt = not ini.main.hpt
inicfg.save(ini)
end)
sampRegisterChatCommand('hphud', function()
ini.main.hphud = not ini.main.hphud
inicfg.save(ini)
end)
end
function cef.onSendCEF(str)
if str:match('onActiveViewChanged|AnimationsMenu') or str:match('vehicleMenu.loadList') then
alpha = 0x26ffffff
alphabg = 0x26000000
alphabar = 0.15
elseif str:match('onActiveViewChanged|') then
alpha = 0xFFffffff
alphabg = 0xff000000
alphabar = 1
end
if str:match('onActiveViewChanged|DonationShop') or str:match('onActiveViewChanged|ArizonaPass') then
visible = false
elseif str:match('onActiveViewChanged|') then
visible = true
end
end
function cef.onDisplayCEF(str)
if str:match('carMenu') then
alpha = 0xFFffffff
alphabg = 0xff000000
alphabar = 1
end
end