IntelSDM / 7DTD

7 Days To Die Hack And Cheat
The Unlicense
53 stars 31 forks source link

Some small improvements #2

Closed Gelleode closed 1 year ago

Gelleode commented 1 year ago

Apparently in Menu you accidentally used wrong function to set SpellPoints and using SetLevel instead.

Also your aim has one small probelm. If ray is colliding with character(For example when you're aiming down from a building/into the hole) it does not see the target so I have looked into the GetExecuteActionTarget and tweaked the code a little so now this function is working properly and i have not noticed bugs yet. However there is one small problem with it still. Demolishers and Mutants aren't always focused onto, presumably because of their armor and weird head texture so need to deal with this one too somehow.

 public static bool GetEntityVisibility(EntityAlive entity, Vector3 pos)
        {
            // -538750997 is from the game's project raycast mask.
            int modelLayer = Globals.LocalPlayer.GetModelLayer();
            Globals.LocalPlayer.SetModelLayer(2, false, null);
            bool flag = Physics.Linecast(
                            Globals.LocalPlayer.cameraTransform.transform.position,
                            pos,
                            out RaycastHit, -538750997) &&
                        RaycastHit.collider &&
                        RaycastHit.transform.position == pos &&
                        RaycastHit.collider.gameObject.transform.root.gameObject == entity.gameObject.transform.root.gameObject;
            Globals.LocalPlayer.SetModelLayer(modelLayer, false, null);

            return flag;
        }

And also there is problem with Player boxes, health bars and basically everything around it. Probably it would work in older versions but nowadays it just shows small pixel of color needed somewhere around shoulder of a player. And as of now i am just a bit lazy to fix it so no code for fixed version of that yet.

Also would be really great if you would be able to see boxes, containers and etc. For now i only found a way to find their(TileEntity) World Position but not how to get Screen Point out of that.

IntelSDM commented 1 year ago

Thanks for contributing. I remember there being one of the menu items assigned with the wrong function. I guess I didn't fix it. After I saw Elijah's pull request I thought the game might have updated. I guess it isn't too abnormal, besides the ReadMe being updated the cheat hasn't been updated since July 2022. With your statement on the Aimbot not targeting certain entities it's likely due to them not being classed as animals or zombies. I noticed many zombies weren't identified as zombies so it's more likely that the entity just isn't on the entity list you're looping for the Aimbot. With your issue with containers if you have the world point you should just be able to throw them through your WorldToScreen function Just looking through the source now, it looks like when I cleaned up the source a few months ago I messed up a few function calls. I guess this calls for an update and another clean-up.

Gelleode commented 1 year ago

As of aimbot - I switched EntityZombie into EntityEnemy so it targets almost everyone hostile and also added additional aim settings for EntityAnimal for me myself. The problem with those zombies is that their models are a bit overlapping over their head pos most of the time which causes some problems with rays.

With containers i've tried to do this but the best i could put looks like this which is quite bad in my opinion. image

As you can see - all the labels are being shown somewhere in specific yet random place(In this case it's outside of a map)

Code to do that one in particular is here

foreach (var tileEntity in EntityList)
{
    if (tileEntity == null)
    continue; // check if TileEntity is valid pointer

    Debug.Log($"TileEntity exists");
    var tileEntityTransformPos = World.blockToTransformPos(tileEntity.ToWorldPos());
    Debug.Log($"Tile Transform Pos: {tileEntityTransformPos.x},{tileEntityTransformPos.y}, {tileEntityTransformPos.z}");

    Vector3 screenposition = Globals.WorldPointToScreenPoint(tileEntityTransformPos);

    Debug.Log($"World Pos: {tileEntity.ToWorldPos().x},{tileEntity.ToWorldPos().y},{tileEntity.ToWorldPos().z}");
    Debug.Log($"Screen position: {screenposition.x},{screenposition.y}");
    if (!(Globals.IsScreenPointVisible(screenposition)))
    continue;

    Debug.Log($"Can be seen: {tileEntity.GetType()}");
    Debug.Log($"At: {tileEntity.ToWorldPos().x},{tileEntity.ToWorldPos().y},{tileEntity.ToWorldPos().z}");
    Debug.Log($"Player Transform: {Globals.LocalPlayer.transform.position.x},{Globals.LocalPlayer.transform.position.y},{Globals.LocalPlayer.transform.position.z}");
    Debug.Log($"Player Position: {Globals.LocalPlayer.position.x}, {Globals.LocalPlayer.position.y}, {Globals.LocalPlayer.position.z}");
    int distance = (int)Vector3.Distance(Globals.MainCamera.transform.position, tileEntity.ToWorldPos());
    string distancestr = $"({distance.ToString()}m)";
    string namestr = $"{tileEntity.blockValue.Block.DisplayType}";

    Drawing.DrawString(new Vector2(screenposition.x, screenposition.y), $"{namestr}{distancestr}", Helpers.ColourHelper.GetColour("Zombie Colour"), true, 12, FontStyle.Normal, 0);
}
IntelSDM commented 1 year ago

As of aimbot - I switched EntityZombie into EntityEnemy so it targets almost everyone hostile and also added additional aim settings for EntityAnimal for me myself. The problem with those zombies is that their models are a bit overlapping over their head pos most of the time which causes some problems with rays.

With containers i've tried to do this but the best i could put looks like this which is quite bad in my opinion. image

As you can see - all the labels are being shown somewhere in specific yet random place(In this case it's outside of a map)

Code to do that one in particular is here

foreach (var tileEntity in EntityList)
{
  if (tileEntity == null)
  continue; // check if TileEntity is valid pointer

  Debug.Log($"TileEntity exists");
  var tileEntityTransformPos = World.blockToTransformPos(tileEntity.ToWorldPos());
  Debug.Log($"Tile Transform Pos: {tileEntityTransformPos.x},{tileEntityTransformPos.y}, {tileEntityTransformPos.z}");

  Vector3 screenposition = Globals.WorldPointToScreenPoint(tileEntityTransformPos);

  Debug.Log($"World Pos: {tileEntity.ToWorldPos().x},{tileEntity.ToWorldPos().y},{tileEntity.ToWorldPos().z}");
  Debug.Log($"Screen position: {screenposition.x},{screenposition.y}");
  if (!(Globals.IsScreenPointVisible(screenposition)))
  continue;

  Debug.Log($"Can be seen: {tileEntity.GetType()}");
  Debug.Log($"At: {tileEntity.ToWorldPos().x},{tileEntity.ToWorldPos().y},{tileEntity.ToWorldPos().z}");
  Debug.Log($"Player Transform: {Globals.LocalPlayer.transform.position.x},{Globals.LocalPlayer.transform.position.y},{Globals.LocalPlayer.transform.position.z}");
  Debug.Log($"Player Position: {Globals.LocalPlayer.position.x}, {Globals.LocalPlayer.position.y}, {Globals.LocalPlayer.position.z}");
  int distance = (int)Vector3.Distance(Globals.MainCamera.transform.position, tileEntity.ToWorldPos());
  string distancestr = $"({distance.ToString()}m)";
  string namestr = $"{tileEntity.blockValue.Block.DisplayType}";

  Drawing.DrawString(new Vector2(screenposition.x, screenposition.y), $"{namestr}{distancestr}", Helpers.ColourHelper.GetColour("Zombie Colour"), true, 12, FontStyle.Normal, 0);
}

In regard to your Aimbot raycast issue, I found that the mutant zombies had a layermask of 15 on their heads but this is the same as a lot of other zombie's body masks. so whitelisting it would mean that the raycast would shoot through zombie bodies which we don't want. So I added a little distance buffer so if it hits the zombie but the point isn't bang on it will still work. The old check for seeing if it was on the point was needed due to it going through players to other players but this should work fine as it checks if the gameobject is the same. New VisCheck:

        public static bool VisbilityCheck(EntityAlive entity, Vector3 pos)
        {
            // -538750997 is from the game's project raycast mask.
            int modelLayer = Globals.LocalPlayer.GetModelLayer();
            Globals.LocalPlayer.SetModelLayer(2, false, null);
            bool flag = Physics.Linecast(
                            Globals.LocalPlayer.cameraTransform.transform.position,
                            pos,
                            out RaycastHit, -538750997) &&
                        RaycastHit.collider &&
                        Vector3.Distance(RaycastHit.transform.position, pos) <= 2 &&
                        RaycastHit.collider.gameObject.transform.root.gameObject == entity.gameObject.transform.root.gameObject;
            Globals.LocalPlayer.SetModelLayer(modelLayer, false, null);

            return flag;
        }

You can use this code here to check the layermasks:

   public static string BarrelRayCastTest()
        {
            try
            {
                    Physics.Linecast(
                  Camera.main.transform.position,
                  Camera.main.transform.forward * 1000,
                  out RaycastHit);
                 return RaycastHit.transform.gameObject.layer.ToString(); // check the layer the raycast hits
            }
            catch
            {
                return "Unkown";
            }
        }
Gelleode commented 1 year ago

Thank you for this additional distance check but i reduced it to 0.7 just in case because zombies tend to be around corner sometimes. Probably i would even add it to some kind of cfg or temp cfg to check which value would work the best

Do you have any ideas on how to find TileEntities on screen?

IntelSDM commented 1 year ago

While researching containers I couldn't help but to notice the TileEntity function:

    public void NotifyListeners()
    {
        for (int i = 0; i < this.listeners.Count; i++)
        {
            this.listeners[i].OnTileEntityChanged(this, this.dataObject);
        }
    }

Seems to be that they are trusting the client to control the flow of network packets between other clients. A MASSIVE networking no no.

That being said I can't find how to access tile entities. I saw a tileentitylist being constructed by utilizing GetEntity with the Entity class:

 foreach (Entity ent in FindObjectsOfType<Entity>().ToList())
                {
                    if (ent == null)
                        continue; // check null or not
                    TileEntityLootContainer container = ent.lootContainer;

                    ContainerList.Add(container); 
                }

I get 9 entities and none of them even draw to screen. Could you tell me where you're getting your EntityList from?

Also regarding your coyness with the additional distance check, the raycast still has to hit the zombie itself. So it won't start validating the visibility when they are behind walls or corners.

Gelleode commented 1 year ago

I get 9 entities and none of them even draw to screen. Could you tell me where you're getting your EntityList from?

EntityList.Clear();
var player = Globals.LocalPlayer;
var playerPos = player.GetBlockPosition();
int num = World.toChunkXZ(playerPos.x);
int num2 = World.toChunkXZ(playerPos.z);
for (int i = -1; i < 2; i++)
{
for (int j = -1; j < 2; j++)
{
Chunk chunk = (Chunk)player.world.GetChunkSync(num + j, num2 + 1);
if (chunk == null)
continue;
Debug.Log($"Chunk - {chunk.X}, {chunk.Z}");
var tileEntities = chunk.GetTileEntities();
for (int k = 0; k < tileEntities.list.Count; k++)
{
TileEntity tileEntity = tileEntities.list[k];
EntityList.Add(tileEntity);
Debug.Log($"Added TileEntity {tileEntity.GetTileEntityType()}");
}
}
}

I've found this in EntityPlayerLocal.updateBlockRadiusEffects() and it founds every single TileEntity around localplayer just fine. Then we can just sort them out by enum TileEntityType to get the ones we actually need. For now i didn't do it but it seems to work.

IntelSDM commented 1 year ago

Ok. So as soon as I set it up I saw the issue. Its about the position's relativity to the chunk. I subtracted the player position from the tile entity position and got a closer distance that was some what near the objects. So the issue is the position being relative to the chunk. Another issue with the code is that your code there only gets the current player chunk(so not very useful for more than 35m). I did some digging and made this:

  foreach (ChunkGameObject chunkobj in Globals.LocalPlayer.world.m_ChunkManager.GetDisplayedChunkGameObjects())
                {
                    Chunk chunk = chunkobj.chunk;
                    var tileentities = chunk.GetTileEntities();
                    for (int k = 0; k < tileentities.list.Count; k++)
                    {
                        TileEntity ent = tileentities.list[k];
                        TileList.Add(ent);
                    }
                }

This will get the entities that are i all your loaded chunks. I am still trying to find a way to fix the relativity issue.

Gelleode commented 1 year ago

I've accidentally pulled your new latest commit into the one i've been working with instead of the clean one so i've lost all my "progress" but there is still a problem with Main menu and skillbtn still gives lvl instead of skillpoints image

IntelSDM commented 1 year ago

Ahh, thanks for reminding me. I forgot about that. Here add my discord Gr33n#5374. An easier way to communicate with me than github issues.

IntelSDM commented 1 year ago

image I have managed to get the correct world position for tiles now:

 BlockEntityData blockentity = tile.GetChunk().GetBlockEntity(tile.ToWorldPos());
Vector3 worldpos = blockentity.transform.position;