-
Автор темы
- #1
Код анализа BSP:
Структуры и получение пути до карты:
Трассировка:
Проверка видимости:
Проверка видимости работает ну слишком медленно, даже медленнее, чем spotted by mask. Так быть не должно. Помогите найти ошибку
Структуры и получение пути до карты:
Python:
def GetPath(mapname):
try:
settings_open = open('settings.txt', 'r')
path = settings_open.read()
except IOError:
print('set csgo path | Example : ...\\common\\Counter-Strike Global Offensive')
path = input()
settings_write = open('settings.txt', 'w')
settings_write.write(path)
settings_write.close()
path += "/csgo/maps/" + mapname + ".bsp"
return path
class VECTOR(Structure):
_fields_ = [("x", c_float),
("y", c_float),
("z", c_float)]
def length(self):
return math.sqrt(self.x * self.x + self.y * self.y + self.z * self.z)
def dotProduct(self, dot):
return self.x * dot.x + self.y * dot.y + self.z * dot.z
def distanceFrom(self, other):
return math.sqrt(((self.x - other.x) ** 2) + ((self.y - other.y) ** 2) + ((self.z - other.z) ** 2))
def __add__(self, other):
return VECTOR(self.x + other.x, self.y + other.y, self.z + other.z)
def __sub__(self, other):
return VECTOR(self.x - other.x, self.y - other.y, self.z - other.z)
def __iadd__(self, other):
self.x += other.x
self.y += other.y
self.z += other.z
return self
def __idiv__(self, other):
if type(other) is VECTOR:
self.x /= other.x
self.y /= other.y
self.z /= other.z
else:
self.x /= other
self.y /= other
self.z /= other
return self
class lump_t(Structure):
_fields_ = [("fileofs", c_int),
("filelen", c_int),
("version", c_int),
("fourCC", c_char * 4)]
class dheader_t(Structure):
_fields_ = [("ident", c_int),
("version", c_int),
("lumps", lump_t * 64),
("mapRevision", c_int)]
class dplane_t(Structure):
_fields_ = [("normal", VECTOR),
("dist", c_float),
("type", c_int)]
class dnode_t(Structure):
_fields_ = [("planenum", c_int),
("children", c_int * 2),
("mins", c_short * 3),
("maxs", c_short * 3),
("firsface", c_ushort),
("numfaces", c_ushort),
("area", c_short)]
class dleaf_t(Structure):
_fields_ = [("contents", c_int),
("cluster", c_short),
("pad_bitfields", c_byte * 2),
("mins", c_short * 3),
("maxs", c_short * 3),
("firstleafface", c_ushort),
("numleaffaces", c_ushort),
("firstleafbrush", c_ushort),
("numleafbrushes", c_ushort),
("leafWaterDataID", c_short)]
Python:
class trace:
def __init__(self, map):
self.handle = open(GetPath(map), 'rb')
self.header = dheader_t()
self.handle.readinto(self.header)
self.planeLump = self.getLumpFromId(1)
self.nodeLump = self.getLumpFromId(5)
self.leafLump = self.getLumpFromId(10)
def getLumpFromId(self, id):
lump = []
if id == 1:
numLumps = self.header.lumps[id].filelen / sizeof(dplane_t)
for i in range(int(numLumps)):
lump.append(dplane_t())
elif id == 5:
numLumps = self.header.lumps[id].filelen / sizeof(dnode_t)
for i in range(int(numLumps)):
lump.append(dnode_t())
elif id == 10:
numLumps = self.header.lumps[id].filelen / sizeof(dleaf_t)
for i in range(int(numLumps)):
lump.append(dleaf_t())
for i in range(int(numLumps)):
self.handle.seek(self.header.lumps[id].fileofs + (i * sizeof(lump[i])))
self.handle.readinto(lump[i])
return lump
def getLeafFromPoint(self, point):
node = 0
while node >= 0:
pNode = self.nodeLump[node]
pPlane = self.planeLump[pNode.planenum]
d = point.dotProduct(
pPlane.normal) - pPlane.dist # d = D3DXVec3Dot(&point, &pPlane->normal) - pPlane->dist;
if d > 0:
node = pNode.children[0]
else:
node = pNode.children[1]
return self.leafLump[-node - 1]
def isVisible(self, vStart, vEnd):
vDirection = vEnd - vStart
vPoint = vStart
iStepCount = int(vDirection.length())
vDirection.x /= iStepCount
vDirection.y /= iStepCount
vDirection.z /= iStepCount
pLeaf = None
while (iStepCount):
vPoint.x -= vDirection.x
vPoint.y -= vDirection.y
vPoint.z -= vDirection.z
pLeaf = self.getLeafFromPoint(vPoint)
if pLeaf:
if (pLeaf.contents & 0x1) or (pLeaf.contents & 0x2) or (pLeaf.contents & 0x8):
break
iStepCount -= 1
return not (pLeaf.contents & 0x1)
Python:
def vischeck(localplayer, entity):
while True:
activemap = pm.read_string(enginepointer + dwClientState_Map)
localpos1 = pm.read_float(localplayer + m_vecOrigin)
localpos2 = pm.read_float(localplayer + m_vecOrigin + 4)
localpos_z_angles = pm.read_float(localplayer + m_vecViewOffset + 0x8)
localpos3 = pm.read_float(localplayer + m_vecOrigin + 8) + localpos_z_angles
aimplayerbone = pm.read_int(entity + m_dwBoneMatrix)
enemypos1 = pm.read_float(aimplayerbone + 0x30 * 5 + 0xC)
enemypos2 = pm.read_float(aimplayerbone + 0x30 * 5 + 0x1C)
enemypos3 = pm.read_float(aimplayerbone + 0x30 * 5 + 0x2C)
MyVector = VECTOR(localpos1, localpos2, localpos3)
EntVector = VECTOR(enemypos1, enemypos2, enemypos3)
traceray = trace(activemap)
isvis = traceray.isVisible(MyVector, EntVector)
return isvis