Advertisement
HR_Shaft

Replace Player Names v1.0 for SAPP

Feb 24th, 2016
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.60 KB | None | 0 0
  1. -- Replace Player Names v1.0 for SAPP
  2. -- by H® Shaft
  3.  
  4. -- This will replace "unwanted names" (line 102) with the "replacement_names" you specify (line 109) and also, notify the player.  
  5. -- You can add names to the table: (replace_table) with the name you want replaced in quotes separated by comma between names.
  6. -- all names are case sensitive: "Smith" is not the same as "smith" - so bad strings can be added to catch multiple names (line 124)
  7. -- This script is a derivation/development of OnNameRequest by Devieth/IT300/Skylace
  8.  
  9. -- Message given to player who had their name replaced and tells them their new name:
  10. REPLACEMENT_MESSAGE = "The server has replaced your name.  Your new name is: "
  11.  
  12. api_version = "1.9.0.0"
  13.  
  14. function OnScriptLoad()
  15.     register_callback(cb['EVENT_PREJOIN'], "OnPlayerPrejoin")
  16.     register_callback(cb['EVENT_GAME_END'],"OnGameEnd")
  17.     if halo_type == "PC" then ce = 0x0 else ce = 0x40 end
  18.     network_struct = read_dword(sig_scan("F3ABA1????????BA????????C740??????????E8????????668B0D") + 3)
  19.     LoadTables()       
  20. end
  21.  
  22. function OnPlayerPrejoin(PlayerIndex)
  23.     local network_struct = read_dword(sig_scan("F3ABA1????????BA????????C740??????????E8????????668B0D") + 3)
  24.     local client_network_struct = network_struct + 0x1AA + ce + to_real_index(PlayerIndex) * 0x20
  25.     local name = read_widestring(client_network_struct, 12)
  26.     local new_name = OnNameRequest(PlayerIndex, name)
  27.     if name ~= new_name then
  28.         write_widestring(client_network_struct, string.sub(new_name,1,11), 12)
  29.         notify_player = timer(6000, "NotifyPlayer", PlayerIndex, new_name)
  30.     end
  31. end
  32.  
  33. function OnNameRequest(PlayerIndex, Name)
  34.     -- find bad strings in player names, add AsIs name to unwanted names
  35.     local AsIs = Name
  36.     local name = string.lower(Name)
  37.     for k,v in pairs(bad_strings) do
  38.         if (string.gsub(name,string.lower(v),"") ~= name) then
  39.             table.insert(unwanted_names, AsIs)
  40.         end
  41.     end
  42.     -- find unwanted player names
  43.     for k,v in pairs(unwanted_names) do
  44.         if v == Name then
  45.             local rand_name = rand(1, #replacement_names+1)
  46.             new_name = string.format("%s",  replacement_names[rand_name])
  47.             table.remove(replacement_names, rand_name) -- prevent duplicate selections 
  48.             Name = new_name
  49.         end
  50.     end
  51.     return Name
  52. end
  53.  
  54. function write_widestring(address, str, len)
  55.     local Count = 0
  56.     for i = 1,len do
  57.         write_byte(address + Count, 0)
  58.         Count = Count + 2
  59.     end
  60.     local length = string.len(str)
  61.     local count = 0
  62.     for i = 1,length do
  63.         local newbyte = string.byte(string.sub(str,i,i))
  64.         write_byte(address + count, newbyte)
  65.         count = count + 2
  66.     end
  67. end
  68.  
  69. function read_widestring(address, length)
  70.     local count = 0
  71.     local byte_table = {}
  72.     for i = 1,length do
  73.         if read_byte(address + count) ~= 0 then
  74.             byte_table[i] = string.char(read_byte(address + count))
  75.         end
  76.         count = count + 2
  77.     end
  78.     return table.concat(byte_table)
  79. end
  80.  
  81. function NotifyPlayer(PlayerIndex, new_name)
  82.     if player_present(PlayerIndex) then
  83.         local name = new_name
  84.         sendresponse(REPLACEMENT_MESSAGE .. name, PlayerIndex)
  85.     end
  86.     return false
  87. end
  88.  
  89. function sendresponse(message, PlayerIndex)
  90.     if (PlayerIndex == nil) or (message == nil) then return end
  91.     if PlayerIndex then
  92.         rprint(PlayerIndex, message)
  93.     end
  94. end
  95.  
  96. function LoadTables()
  97. -- UTF8 character code for '%+%'
  98. autogen = "\43\37\43"
  99.  
  100. -- unwanted names: case sensitive ("Bob" is not the same as "bob")
  101. -- most of these names are auto-generated by halo (english install), or are common noob names you wish to replace
  102. unwanted_names = {autogen, "+%+", "Donut", "Penguin", "Stumpy", "Whicker", "Shadow", "Howard", "Wilshire", "Darling", "Disco", "Jack", "The Bear", "Sneak", "The Big L", "Whisp",  
  103.                 "Wheezy", "Crazy", "Goat", "Pirate", "Saucy", "Hambone", "Butcher", "Walla Walla", "Snake", "Caboose", "Sleepy", "Killer", "Stompy", "Mopey",  
  104.                 "Dopey", "Weasel", "Ghost", "Dasher", "Grumpy", "Hollywood", "Tooth", "Noodle", "King", "Cupid", "Prancer", "POQ Sucks"
  105.                 }
  106.  
  107. -- new replacement names to replace unwanted names.  
  108. -- new names CANNOT be more than 10 characters long! Each entry must be in "quotes" and a comma between entries.
  109. replacement_names = {"Beau", "Bobby Joe", "Bodean", "Bubba", "Buck", "Cletus", "Cleon", "Billy Bob", "Beauford", "Jethro", "Orville", "Joe Bob", "Bucephelus", "Wilford", "Clyde",
  110.     "Delmont", "Duke", "Eustice", "Earl", "Floyd", "Forrest", "Jim Bob", "Jimmy Don", "John Boy", "Otis", "Pervis", "Roscoe", "Saggory", "Rufus", "Tiberius", "Billy Bo Bob", "Bubba, Jr.",
  111.     "Cooter", "Elrod", "Jed", "Jebediah", "Junior, Jr.", "Bubba, Jr.", "Gunther", "Ellie Mae", "Sue Ellen", "Earlene", "Bertha", "Peggy Sue", "Daisy Mae", "Henrietta", "Annabelle", "Bambi", "Betty Jo",
  112.     "Betty Lou", "Billie Jean", "Bobbie Sue", "Buffy", "Claudette", "Delilah", "Georgette", "Jaylnn Jo", "Jozelle", "Hattie", "Layla", "Linda Sue", "Martha-Mae", "Roxxy", "Peach", "Tucker",
  113.     "Patty Sue", "Shaneyney", "Trixibelle", "Waynelle", "Beaula", "Brandine", "Larlene", "Lilah", "Savannah", "Shelbylyn", "Lula", "Abner", "Barney", "Cal", "Chester", "Cy", "Cyrus", "Gus", "Homer",
  114.     "Ike", "Jasper", "Jeb", "Jethro", "Lem", "Luke", "Wilbur", "Willie", "Zeb", "Zed", "Zeke", "Hayseed", "Big Daddy", "West", "Les", "Meatloaf", "Uncle Ben", "Ronda", "Cherry", "Shawnda", "Vonda",
  115.     "Destiny", "Claudine", "Dreama", "EvaJo", "Faylene", "Gracelyn", "January", "Jazlean", "Kaylin", "Loribelle", "Misty Dawn", "Norma", "Raylene", "Rubyjane", "Sapphire", "Sheena", "Summer", "Sunset",
  116.     "Tabitha", "Vanity", "Kandy", "Erneshia", "Jicelle", "Mandy Lynn", "Misty Rain", "Amaleen", "Baylie", "Brittney", "Tits McGee"
  117.     }
  118.  
  119. -- bad strings, Only lowercase! if a 'portion' (string) of these bad names enter, add players entry name to unwanted_names table, then replace
  120. -- example: "nigg" as a bad name will catch "nigger", "nigga" and "nigguh",  
  121. -- whereas, a player named "grape" will have name replaced because "rape" is a bad name
  122. -- if "ass" was listed here (it's not), a player named Assassin would have their name replaced,
  123. -- "assh" is listed, so a player named "asshole" or "asshat" would have their name replaced
  124. bad_strings = {"fuck", "fuk", "shit", "bitch", "cock", "cok", "cunt", "nigg", "jew", "rape", "vehic", "puss", "rapist", "negro", "spic", "wetback",
  125.             "your mom", "madre", "new00", "nuevo", "phuck", "phuk", "assh", "mike hunt", "penis", "dick", "vagina"
  126.             }  
  127. end
  128.  
  129. function OnScriptUnload()
  130.     unwanted_names = {}
  131.     replacement_names = {}
  132.     bad_strings = {}
  133. end
  134.  
  135. function OnGameEnd()
  136.     --re-populates replacement_names table
  137.     LoadTables()
  138. end
  139.  
  140. function OnError(Message)
  141.     print(debug.traceback())
  142. end
  143.  
  144. -- Created by H® Shaft
  145. -- Visit http://halorace.org/forum/index.php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement