Skip to content

Instantly share code, notes, and snippets.

@ChadSki
Created October 24, 2014 01:48
Show Gist options
  • Save ChadSki/9be3407a78aa908ed7ab to your computer and use it in GitHub Desktop.
Save ChadSki/9be3407a78aa908ed7ab to your computer and use it in GitHub Desktop.
Discussion of the Implementation of No-Lead in SAPP

SAPP 5.0 Is out, by now every1 should got it by auto-update.

There are 1 main change in the engine, that hooking is now totally rewritten, code is more clear and hooking is faster. This means Sapp is some step closer to port to HPC. Sapp also got 2 new feature: arguments for custom commands and The no-lead mod. =)

Arguments for custom commands: Between the command name and the command, you can put arguments starting with the '#' character. Example: You add to the commands.txt the max #n 'sv_maxplayers #n' line and you execute the max 4 command, sapp will execute the sv_maxplayers 4 command. Or spawnw #n #weap 'spawn weap "weapons#weap#weap" #n; wadd #n' and you execute the spawnw 4 "sniper rifle" it will execute the spawn weap "weapons\sniper rifle\sniper rifle" 4 and the wadd 4 command, and gives a sniper for player 4. Here I had to note that lately kids using sapp to cheat on scrims. There is a feature to fix this already: Scrim Mode: "scrim_mode [enabled]: If enabled, no one can execute any naughty commands. Server sends a message to every player if this status is changed. You can also check it's status with the info command." Ask the admins to turn this function ON with scrim_mode 1 command if it's not enabled. If they try to turn it off during the game, server will alert the players. If they reject to enable it or change it meanwhile just leave them there cuz they prolly only want to cheat.

No Lead Mode: Story (for advanced players): At 2012. July 25. Btcc22 added me that he has some questions about "Halo's inner-workings", soon he told me that he has some idea to reduce/fix leading. The idea was collecting the player's state on each tick and storing it in a buffer of historical data and restore the old positions for the collision check function, using the players' ping as an index. Since I already had the collision-check function, (THX to Skyline, he gave me the address, originally for the boost command, but I'm using it for Aimbot-detection and now for this!), and I was very curious + already had the necessary hooks in SAPP. Only had to add 2 more CC, and since it worth that few hours to try, I decided to code it. Surprising (after few fixes) it worked pretty fine, I wasn't really expecting such improvements, although it still had problems. One was the crashing. It always crashed after few hours of uptime, especially with vehicles. I couldn't figure out the problem + summer was coming so I abandon the project. Also because I though it divides the community, cuz there will be always ppl who hate it and say things like "It's not Halo anymore" etc.

I didn't bother with it anymore until PaulusT posted his mod and every1 was like "wow this is so awesome" etc. I checked his code and liked his idea, but I though mine works fine too, and seeing the positive reactions I migh cold improve mine even more and fix the crashes. It was about 2 weeks ago. So then, I started to work on it again. First, I wanted to fix the crashes, but couldn't find the problem. Long hours of debugging with olly, tried many places for hooking and collecting history etc. but couldn't find the bug. Meanwhile Btcc found where Halo's thread sleeps. I couldn't find it before, since its in call esi format, and olly doesn't reference it, and also cuz for some reason Halo CE calls SleepEx. Well, here I was playing a bit with the code, and now it was clear why Halo dedi uses so many CPU. I managed to run Halo thread in 120 times / sec while the CPU usage is reduced to about half and pings staid stable. This is the part of Sapp 5.0 too, thats why pings go by about 8,333 instead of 33,333 in Sapp servers. Note that this doesn't affects physic or amount of packet's sent. The "only" benefit is that pings are more realistic now and packets are processed faster, which improves reg. One day later I searched for where Halo updates pings, and changed it from every 3 second to every 1. Unfortunately this causes a little bug that I didn't bother fixing yet: player's ping higher than 1000ms "goes crazy" and looks like their ping changing from 1-1000. It's because Halo process the previous ping packet as it was the latest one.

Anyways, I also set Halo's thread priority to "Time Critical" for more stable pings and for the better reg. By then it worked so well (apart from crashes) that I realized another problem (that Btcc knew from the first day tbh. lol); the reg was very bad at high pings. He told me that this is prolly cause bullet-magnetism, since Halo "corrects" the bullet's vectors based on the original positions, not on the restored one. By adding 1 more CC to fix this, crashes and lags made the whole mod useless, even if it's worked fine, server couldn't run more than few hours. After long hours of debugging and headaches, figured out that the problem is that the player-object's structure's place in the memory is not only change after die, but sometimes when the player is still alive. I used the pointers that I "extracted" at the spawning, to evade calculating it every time when I want to read/write from/to the player's structure. Like have to use this code every time to get the current pointer: "Dynamic_Player Player = (Dynamic_Player)ObjectTableArray[PlayerTable.ObjectIndexNum]->Offset;"

So, I just removed this kind of "caching" and it was stable finally. Some other days of testing and improving code, and it was done, and released! As you can see, this project wouldn't come true without Btcc22 and his help. I also would like to thank his time testing it, just like for Sean Aero, Ausprime, Persistent, Kadem, Osmo and the others who played in our server and told us their opinion/impression about the mod. ^^ Also, Thanks for Gijs, Ausprime and Persistent for hosting me the servers where we could test it, without them I couldn't really test in other servers, and for high pings. Btw. Btcc would did this too later, but he's working on HAC 2 atm, which has many awesome features that you will see soon. :P

Edit: I forgot an important part. This fix works with any pings (as long as you don't lag), and also works with animations like melee, jumping, crouching, falling etc, but doesn't work with vehicles, yet.

Usage: This one is very simple. This mod is disabled by default, you can enable/disable it with the no_lead [enabled] command, (so just put no_lead 1 to sapp's init.txt to enable it.) You can check and change the state of leading with the lead command. If the admins didn't enable no-lead mod, you can't turn it on for yourself, but if they enabled it, everyone can disable this mod for themselves by typing /lead 1 to the chat. Also, you can re-enable it ofc with the /lead 0 command).

Hehe, such a long post ^^ I hope you'll enjoy it as much as I enjoy creating SAPP =)

Download: http://www.xgclan.com/sapp/index.php/download

Last edited by sehe; October 28th, 2012 at 06:29 PM.

@ChadSki
Copy link
Author

ChadSki commented Feb 22, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment